How to make only the parent gameobject invisible ?

Hi all,
In my Unity Scene I have a Gameobject which contains a lot of children Gameobjects. Now if a certain trigger is set I would like to make only the parent invisible so that the children still exists in the scene (so not disable the parent) . I tried to do
youbot.GetComponent().enabled = false;
but it seems that my gameobject ( the youbot) dont have a renderer but one of the child has, so the parent gameobject is still visible. Can someone suggest a solution to this? Hope for your help and many thanks !

@neymar4138 what you are saying doesn’t make sense per se: If the parent GameObject doesn’t have a renderer, it’s not visible anyway, since it’s the renderer component that makes something visible in the scene in the first place.


In general, if you want to make something invisible, you must access its renderer component and disable it.
So, in your case, you need to find which renderer is rendering what represents the parent GameObject (maybe a child of the parent), access its renderer, and disable it.

void OnTriggerEnter(Collider other)
{
for (i=0; i<= transform.childcount; i++)
{
transform.GetChild (i).gameObject.SetActive (false);
}

}