Created
December 19, 2018 22:40
-
-
Save UtMan88/6ce6f3167dec9fb7f55cb618e9b7c88c to your computer and use it in GitHub Desktop.
When the object in the scene becomes enabled, all objects in "observedObjects" will become Enabled/Disabled based on their SetActiveOnEnable flag. Handy for turning things on/off when starting a scene.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SetActiveOnEnable : MonoBehaviour { | |
[System.Serializable] | |
public class ObservedObjects | |
{ | |
public GameObject gameObject; | |
public bool SetActiveOnEnable = false; | |
} | |
[SerializeField] | |
ObservedObjects[] observedObjects; | |
// Use this for initialization | |
void OnEnable () | |
{ | |
foreach(var obj in observedObjects) | |
{ | |
obj.gameObject.SetActive(obj.SetActiveOnEnable); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment