Activating GameObjects

Tutorial

·

Beginner

·

+10XP

·

5 mins

·

(2660)

Unity Technologies

Activating GameObjects

How to handle the active status of GameObjects in the scene, both independently and within Hierarchies, using SetActive and activeSelf / activeInHierarchy.

This tutorial is included in the Beginner Scripting project.

Previous: Enabling and Disabling GameObjects

Next: Translate and Rotate

Languages available:

1. Activating GameObjects

ActiveObjects

using UnityEngine;
using System.Collections;

public class ActiveObjects : MonoBehaviour
{
    void Start ()
    {
        gameObject.SetActive(false);
    }
}

CheckState

using UnityEngine;
using System.Collections;

public class CheckState : MonoBehaviour
{
    public GameObject myObject;
    
    
    void Start ()
    {
        Debug.Log("Active Self: " + myObject.activeSelf);
        Debug.Log("Active in Hierarchy" + myObject.activeInHierarchy);
    }
}

Complete this tutorial