using System.Collections; using System.Collections.Generic; using UnityEngine; namespace MoreMountains.Tools { /// /// Use this class to enable or disable other gameobjects automatically on Start or Awake /// [AddComponentMenu("More Mountains/Tools/Activation/MMActivationOnStart")] public class MMActivationOnStart : MonoBehaviour { /// The possible modes that define whether this should run at Awake or Start public enum Modes { Awake, Start } /// the selected mode for this instance public Modes Mode = Modes.Start; /// if true, objects will be activated on start, disabled otherwise public bool StateOnStart = true; /// the list of gameobjects whose active state will be affected on start public List TargetObjects; /// /// On Awake, we set our state if needed /// protected virtual void Awake() { if (Mode != Modes.Awake) { return; } SetState(); } /// /// On Start, we set our state if needed /// protected virtual void Start() { if (Mode != Modes.Start) { return; } SetState(); } /// /// Sets the state of all target objects /// protected virtual void SetState() { foreach (GameObject obj in TargetObjects) { obj.SetActive(StateOnStart); } } } }