Lets say you have a GM gameobject, and his 2 childs are “TunnelYellow” and “TunnelBlue” i want to disable Yellow and enable Blue at the same time. How do i disable only Yellow’s renederer using code (C#) through the GM object (their perent)?
Thanks in advance!
Use transform.Find(“name”) to get a child with specific name from a parent and use its renderer to enable or disable it.
Use something like this
void EnableYellow() { transform.Find("TunnelYellow").renderer.enabled=true; transform.Find("TunnelBlue").renderer.enabled=false; } void EnableBlue() { transform.Find("TunnelBlue").renderer.enabled=true; transform.Find("TunnelYellow").renderer.enabled=false; }
Calling EnableYellow() will enable yellow tunnel and automatically disable blue tunnel and calling function EnableBlue will do the opposite