- Home /
 
How can I stop an animator playing
I have 4 buttons, each with a flashing opacity animation that I have rigged up to play when the button is clicked. However when a second button is playing, the one first clicked, still plays and flashes on. And that continues when more buttons are clicked. I have tried using loops, animation components rather than animators and a few other methods. Here is the code, could someone please tell me how I can stop the animation playing when another button is pressed?
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");
     }
 }
 
              Your answer
 
             Follow this Question
Related Questions
How To Play Animation On UI Button Click Please... Im Going To Freak Out Please Enter And Help Me 2 Answers
Playing different button animation after first animation plays 1 Answer
mouse clicked on object animation c# 1 Answer
Button Opacity Animation Not Working 0 Answers
Unity 4.6 UI Button Click Animation? 4 Answers