update sprites for multiple similar objects. Need help
Hi guys,
I am new to unity and I am trying to update multiple coin sprites in a game. Where all of them look the same and need to be changed to different sprite based on an IF condition.
I am able to change sprites of single objects but unable to change for multiple objects in one go. So i would like to know whats the best way to do this.
for single game object i am using GetComponent ()sprite = NewSprite;
Answer by hexagonius · Sep 12, 2015 at 10:00 PM
child all coins to one gameobject. put the script on the new parent. instead of GetComponent use GetComponentsInChildren. iterate the returned list and change each item.
Will it also work if I have sprites under gameObject which is under another gameObject?
GetComponentsInChildren traverses the whole hierarchy from its root callee, so yes, it will also fetch those
Your answer
Follow this Question
Related Questions
MissingFieldException: UnityEngine.SpriteRenderer.sprite 0 Answers
Get sprite size and position 0 Answers
the image set on the inspector is not displayed. I am a beginner 2 Answers
Change sprite size programmatically 0 Answers
Flipping a sprite on a network 0 Answers