Unity – Activating GameObjects

Activate Object

DRAG AND DROP this script over a object in the Hierarchy:

#pragma strict

function Start ()
{
    gameObject.SetActive(false); // Deactivate an object
}

Check State

Create an object in the scene and give it the name ‘GreatObject’

Create this Script and give it the name ‘MyScript’

#pragma strict

public var myObject :GameObject;


function Start ()
{
    Debug.Log("Active Self: " + myObject.activeSelf);
    Debug.Log("Active in Hierarchy" + myObject.activeInHierarchy);
}

1. DRAG AND DROP this script over ‘GreatObject’ in the Hierarchy
2.Select the ‘GreatObject’> Inspector> MyScript> myObject> the slot is ‘None’, on the right ‘Select Game object’ small icon> Scene> select ‘GreatObject’ from the scene, NOW ‘public var myObject = GreatObject’, you will Debug.Log it

NOTICE:

– if you disable a PARENT object also CHILD will be disabled.
– if you disable a CHILD object the PARENT does not change his original status.