Home Game Development unity – How to vary sprites for a number of baby object from a mother or father?

unity – How to vary sprites for a number of baby object from a mother or father?

0
unity – How to vary sprites for a number of baby object from a mother or father?

[ad_1]

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

I’ve a mother or father object, and I need to change it is baby objects randomly. This is the hierarcy:
hierarchy

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

public Sprite[] sprites;

void Update()
{
    RandomizeSprites();
}

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

This at present solely works for the primary baby object.

Can anybody assist me find out how to do it for each?
Thank you prematurely!

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here