Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animator array or List how to

Discussion in 'Scripting' started by panim0_unity, Jan 17, 2020.

  1. panim0_unity

    panim0_unity

    Joined:
    Nov 13, 2018
    Posts:
    47
    I am trying to make a skill button which will increase attack speed. I planned to do that by changing animator speed but these lines are not working whats my mistake here?

    Code (CSharp):
    1.  List<Animator> animators;
    2.     GameObject[] units;
    3.  
    4. void Start()
    5.     {
    6.         animators = new List<Animator>();
    7.         units = GameObject.FindGameObjectsWithTag("Player1");
    8.         for(int i = 0; i < units.Length; i++)
    9.         {
    10.             animators.Add(units[i].GetComponent<Animator>());
    11.         }
    12.      
    13.     }
    14.  
    15. public void AttackSpeed()
    16.     {
    17.         for(int i = 0; i < units.Length; i++)
    18.         {
    19.             animators[i].speed = 2;
    20.         }
    21.        
    22.         StartCoroutine("CountdownAttackSpeed");
    23.     }
    24. IEnumerator CountdownAttackSpeed()
    25.     {
    26.         int counter = 4;
    27.         while (counter > 0)
    28.         {
    29.             yield return new WaitForSeconds(1);
    30.             counter--;
    31.         }
    32.         if (counter == 0)
    33.         {
    34.             for (int i = 0; i < units.Length; i++)
    35.             {
    36.                 animators[i].speed = 1;
    37.             }
    38.         }
    39.     }
     
  2. panim0_unity

    panim0_unity

    Joined:
    Nov 13, 2018
    Posts:
    47
    Sorry I could not figure out how to close this thread. I just solved my problem
     
  3. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,114
    It's a good idea to always post how you managed to solve your problem, because if others should run into the same problem later on and they happen upon this thread, it might help them out.