Thursday, October 6, 2022
HomeGame Developmentunity - Easy methods to change sprites for a number of baby...

unity – Easy methods to change sprites for a number of baby object from a guardian?


I’m not a lot of an skilled, tried to search for for options however I by no means discovered any that I may use.

I’ve a guardian object, and I need to change it is baby objects randomly. That is the hierarcy:
hierarchy

I need to change each the “Roof” and the “Constructing” sprites randomly.
That is how my code appears like proper now:

public Sprite[] sprites;

void Replace()
{
    RandomizeSprites();
}

public void RandomizeSprites()
{
    random = Random.Vary(0, sprites.Size);
    GetComponentInChildren<SpriteRenderer>().sprite = sprites[random];
}

This at the moment solely works for the primary baby object.

Can anybody assist me how you can do it for each?
Thanks upfront!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments