条件结束后如何停止音障?

时间:2014-05-24 19:24:19

标签: c# audio unity3d

我正在Unity中制作一款游戏,而且我在向敌人添加音频时遇到了一些问题。我有一个用于行走,攻击和死亡的音频剪辑。但是当我玩游戏时,音频片段开始在正确的条件下播放,但它们永远不会像我期待的那样停止。我希望他们只在他们处于正确状态时才能比赛,并在另一个状态下停止比赛。

这是我的代码:

public override void ActionCharacter(){

    if (!isDead) {

        currentTimeToChangeAction += Time.deltaTime;

        if (currentDistanceToPlayer <= distanceToAttack && currentTimeToAttack < timeToAttack) {
            currentTimeToAttack += Time.deltaTime;
            inAttack = true;
            axiVertical = 0;
            audio.PlayOneShot(ZombieWalkAudio);
            animationCharacter.CrossFade (attackAnimation.name);
        } else {
            currentTimeToAttack = 0;
            inAttack = false;
        }

        if (inStun) {
            currentTimeToStun += Time.deltaTime;
            if (currentTimeToStun > timeToStun) {
                currentTimeToStun = 0;
                inStun = false;
            }
            axiVertical = 0;
            animationCharacter.CrossFade (damageAnimation.name);
        }

        if (!inAttack && !inStun) {
            if (currentTimeToChangeAction > timeToChangeAction) {
                currentTimeToChangeAction = 0;
                //axiHorizontal = Time.deltaTime * walkVelocity;
                axiVertical = Time.deltaTime * walkVelocity;
                audio.PlayOneShot(ZombieAttackAudio);
            }

            if (currentDistanceToPlayer <= distanceMinToRun) {
                callRun = true;     
            } else {
                callRun = false;    
            }

            transform.LookAt (player.transform);
            //currentGun.Shoot();
        }
    }
}

0 个答案:

没有答案