Archive

Archive for July, 2011

A Simple script to show or hide children object in Unity 3D

July 1, 2011 Leave a comment

This is a simple script to show or hide children object in Unity 3D.
For example, you can create empty Object, then add Sphere and Box as the children of it.
Just attach this script to that empty object, then you can show or hide the sphere and the box.

using UnityEngine;
using System.Collections;

public class UnrenderObjScript : MonoBehaviour
{

Renderer[] listOfChildren;

void OnGUI()
{

if(GUILayout.Button(“Hide”))
{
listOfChildren = GetComponentsInChildren<Renderer>();
foreach(Renderer child in listOfChildren)
{
child.enabled = false;

}

}

if(GUILayout.Button(“Show”))
{

listOfChildren = GetComponentsInChildren<Renderer>();
foreach(Renderer child in listOfChildren)
{
child.enabled = true;

}

}

}

}

Categories: Game and CG