gameObject.GetComponent<SpriteRenderer>().sprite = Characters[0];

        gameObject.GetComponent<SpriteRenderer>().sprite = Characters[1];
        gameObject.GetComponent<SpriteRenderer>().sprite = Characters[2];

This is my current script, which changes character at keypress Y, U, and I. However as I am developing for touch, I want them to change when a box at the screen is pressed (Left one):

enter image description here

How can I proceed with this? Can I set the sprites to numbers, and let's say at button press, it adds +1, and that changes the sprite? And if so, how does the last one work to get it back at 0? Appriciate all answers. :)


1 Answer 1


Something like this:

if (selected_character >= num_characters)
    selected_character = 0;

and you can select the sprite by

gameObject.GetComponent<SpriteRenderer>().sprite = Characters[selected_character];

You also have to declare a new class member to make the code above work:

int selected_character = 0;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .