- Home /
Change render of all children
I am trying to fade in some 3D text. Problem is I have multiple 3D objects that all need to fade in. I don't want to attach a script to each object that calls the update function.
Here is what I want to do (but don't know how to do it).
create an empty gameObject and place each 3Dtext as a child of that gameObject.
Create a script that will be on the gameObject that will access each child's render component and change the alpha value.
Can anyone show me a piece of code to get this working? I think I have the correct logic but not sure how to write it properly in C#.
I am programing in c#
Answer by Key_Less · Nov 20, 2013 at 12:45 AM
This will give you access to all the child renderers that are parented to your empty GameObject.
Renderer[] renderers = GetComponentsInChildren<Renderer>();
foreach (var r in renderers)
{
// Do something with the renderer here...
r.enabled = false; // like disable it for example.
}
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Instantiate as children of GameObject hit by raycast. 2 Answers
Child object of another GameObject invisible or inactive @ runtime 2 Answers
Rotating a parent-child pair 2 Answers
Choosing a random child with tag. 1 Answer