Skip to content

Instantly share code, notes, and snippets.

@UtMan88
Created December 19, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UtMan88/6ce6f3167dec9fb7f55cb618e9b7c88c to your computer and use it in GitHub Desktop.
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.
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