i have a sprite set as a child of a gameobject and i want to get the spriterenderer from that sprite in a script on the gameobject so i can set the color through code, how would i do this?
If there’s just one child object that has a SpriteRenderer, you could use GetComponentInChildren(). Note: if the parent also has a SpriteRenderer it’ll return the parent!
There’s example code here: Unity - Scripting API: Component.GetComponentInChildren
You’d substitute SpriteRenderer in place of HingeJoint.
If it’s a more complex situation (SpriteRenderer also on parent, many children have SpriteRenderers), you might want to expose a public field SpriteRenderer so you can wire it up in the Inspector. Otherwise, your options are getting a particular child by name or index then using GetComponent on that specific child.
Changing the color is very easy: spriteRenderer.color = Color.red;
Thanks for the Note. I had my SpirteRenderer deactivated on my parents. When I removed it solved my problem.