- Home /
Question by
Kato · Jan 07, 2013 at 03:05 PM ·
get component
A simple Question about enabling MeshRenderer of a Child
Hello,
i added to a prefab a plane wish i want to disable/enable now over his Mesh Renderer, the script for that i added direct to the prefab it self.
Comment
Best Answer
Answer by $$anonymous$$ · Jan 07, 2013 at 03:40 PM
Suppose your child object's name is "Plane". Then you can go like this in your script:
public void SetPlaneRendererEnabled(bool enabled)
{
transform.Find("Plane").renderer.enabled = enabled;
}
transform.Find(name)
searches the object's children (including the calling object). You can also do it by setting up a reference to the renderer in the Start()
method.
You're welcome. Then mark it as answer, so others can see your question's been answered. Also make this "answer" a comment on the actual answer :) You can do it from the "more" button.