Answer the question
In order to leave comments, you need to log in
How to change the sprite to the second one when pressing the button and vice versa?
Is it possible to do this in one script? I did not find how to change the sprite on the button in both directions without creating a 2nd button or 2 scripts.
Answer the question
In order to leave comments, you need to log in
The code:
public SpriteRenderer sr;
public Sprite[] sprites;
public void OnButton()
{
// C условием что в SpriteRenderer со старта первый спрайт, и у спрайтов разные Name
int index = (sr.sprite.name == sprites[0].name) ? 1 : 0;
sr.Sprite = sprites[index];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question