- Home /
Question by
Babilinski · Oct 30, 2011 at 11:57 PM ·
childrenderonoff
turn on and off the render of a child
I to get the components from a child and set it to falls. so that my renderer.enabled = false;. I use C#
if (selectedTarget.tag.Equals("Dad")){
a = transform.Find("ring").gameObject;
a.renderer.enabled = true;
does not work. I get a "The name `a' does not exist in the current context " error.
please help
Comment
Answer by gfr · Oct 31, 2011 at 12:03 AM
GameObject a = transform.Find("ring").gameObject;
// ^^^^^^^
Yeah, you should just be using
if(selectedTarget.tag == "Dad")
also, if there isn't an object in the transform hierarchy called "ring", it will also produce a null reference exception, and if that object does not have a renderer then that too will produce a null reference exception.
Your answer
![](https://koobas.hobune.stream/wayback/20220613025125im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting GUI texture on and off 0 Answers
Turn on/off Script 3 Answers
Turn On and Off Lights Via Script 1 Answer