- Home /
How to get a customizatble sprite to animate alternate parts?,How do I get my characters eyes to move when I push play?
I've made a 2d sprite that I have animated using unity's 2D animator. I have also made a small script that lets me change the eyes of my character, by clicking through a short list. When I play the animation through the animator it works perfectly, but when I click the play button every part of the sprite moves except the eyes.
below is the script I made to swap the eyes:
public class ChangingAppearance : MonoBehaviour { public SpriteRenderer part; public Sprite[] options; public int index; void Update() { for (int i = 0; i < options.Length; i++) { if (i == index) { part.sprite = options[i]; } } } public void Swap() { if (index < options.Length - 1) { index++; } else { index = 0; } } }
Thanks for any assistances anyone can provide and I'd be happy to provide more information if needed. ,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:
public class ChangingAppearance : MonoBehaviour
{
public SpriteRenderer part;
public Sprite[] options;
public int index;
void Update()
{
for (int i = 0; i < options.Length; i++)
{
if (i == index)
{
part.sprite = options[i];
}
}
}
public void Swap()
{
if (index < options.Length - 1)
{
index++;
}
else
{
index = 0;
}
}
}
Any help would be much appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220612200647im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Unity is ignoring Sprite Renderer's alpha channel. 0 Answers
How to stretch a sprite in 2d? 1 Answer