如何阻止动画师在Unity中玩

时间:2015-09-16 08:09:10

标签: animation button unity3d click opacity

[解决]

我有4个按钮,每个按钮都有一个闪烁的不透明度动画,当点击按钮时我已经装配好了。但是,当第二个按钮正在播放时,首先单击该按钮,仍然会播放并闪烁。单击更多按钮时会继续。我尝试过使用循环,动画组件而不是动画师和其他一些方法。这是代码,有人可以告诉我如何在按下另一个按钮时停止播放动画吗?

public EnemyBehavior enemyBehavior;
    public bool[] difficultySelected;

    public Animator easy;
    public Animator normal;
    public Animator hard;
    public Animator expert;

    public void DifficultySelected(int name){
        difficultySelected[0] = false;
        difficultySelected[1] = false;
        difficultySelected[2] = false;
        difficultySelected[3] = false;
        difficultySelected[name] = true;
    }

    void Start () {

    }

    void Update () {
        if(difficultySelected[0] == true){
            enemyBehavior.shotsPerSecond = 0.2f;
            easy.Play("Difficulty");
        }else if(difficultySelected[1] == true){
            enemyBehavior.shotsPerSecond = 0.5f;
            normal.Play("Difficulty");
        }else if(difficultySelected[2] == true){
            enemyBehavior.shotsPerSecond = 1;
            hard.Play("Difficulty");
        }else if(difficultySelected[3] == true){
            enemyBehavior.shotsPerSecond = 2;
            expert.Play("Difficulty");
        }
    }

更新

if(difficultySelected[0] == true){
            enemyBehavior.shotsPerSecond = 0.2f;
            normal.StopPlayback();
            hard.StopPlayback();
            expert.StopPlayback();
            easy.Play("Difficulty");
        }else if(difficultySelected[1] == true){
            enemyBehavior.shotsPerSecond = 0.5f;
            easy.StopPlayback();
            hard.StopPlayback();
            expert.StopPlayback();
            normal.Play("Difficulty");
        }else if(difficultySelected[2] == true){
            enemyBehavior.shotsPerSecond = 1;
            easy.StopPlayback();
            normal.StopPlayback();
            expert.StopPlayback();
            hard.Play("Difficulty");
        }else if(difficultySelected[3] == true){
            enemyBehavior.shotsPerSecond = 2;
            easy.StopPlayback();
            normal.StopPlayback();
            hard.StopPlayback();

0 个答案:

没有答案