Search Unity

How do I get my characters eyes to move with the rest of the animation when I press play?

Discussion in 'Animation' started by blazingbrad01, May 3, 2019.

  1. blazingbrad01

    blazingbrad01

    Joined:
    Apr 17, 2019
    Posts:
    5
    I've made a little customization window for my character that allows you to change his eye type. I've also got an idle animation I made using the unity 2d animator. the animation plays fine when I press play on the animator, but when I go to play the game the animation for the eyes doesn't work.
    code I used to swap eye sprites:


    Code (CSharp):
    1. public class ChangingAppearance :  MonoBehaviour
    2.     {
    3.  
    4.         public SpriteRenderer part;
    5.         public Sprite[] options;
    6.         public int index;
    7.  
    8.         void Update()
    9.         {
    10.             for (int i = 0; i < options.Length; i++)
    11.             {
    12.                 if (i == index)
    13.                 {
    14.                     part.sprite = options[i];
    15.                 }
    16.             }
    17.         }
    18.  
    19.  
    20.         public void Swap()
    21.         {
    22.             if (index < options.Length - 1)
    23.             {
    24.                 index++;
    25.             }
    26.             else
    27.             {
    28.                 index = 0;
    29.             }
    30.         }
    31.     }
    Any help would be much appreciated.
     
    Last edited: May 3, 2019