Activating Game Objects

Evidence

Script #1

using System.Collections;
using UnityEngine;

public class script : MonoBehaviour 
{

    void Start () 
    {
        gameObject.SetActive(false);
    }
}

Script #2

using System.Collections;
using UnityEngine;

public class scriptscript : MonoBehaviour 
{
    public GameObject myObject;

    // Use this for initialization
    void Start() 
    {
        Debug.Log(“Active Self: “ + myObject.activeSelf);
        Debug.Log(“Active in Hierarchy: “ + myObject.activeInHierarchy);
    } 
}

Screencast

What I Learned

After watching this tutorial I learned how to activate game objects in a scene using SetActive and activeSelf / activeInHierarchy tools. This helped me learn some new code that could be useful in the future. One problem I had to solve was at first I didn’t realize I had two scripts that were supposed to be for two separate objects located as a component for only one object. It took me a couple minutes of searching to locate the problem and fix which script was attached to which object, but after I figured that out the objects acted just as they were supposed to.

Leave a Reply

Your email address will not be published. Required fields are marked *