using System.Collections; using System.Collections.Generic; using UnityEngine; namespace MoreMountains.Tools { /// /// This component lets you parent the transform you put it on to any target parent (or to the root if none is set), on Awake, Start or anytime you call its Parent() method /// public class MMParentingOnStart : MonoBehaviour { /// the possible modes this can run on public enum Modes { Awake, Start, Script } /// the selected mode public Modes Mode = Modes.Awake; /// the parent to parent to, leave empty if you want to unparent completely public Transform TargetParent; /// /// On Awake we parent if needed /// protected virtual void Awake() { if (Mode == Modes.Awake) { Parent(); } } /// /// On Start we parent if needed /// protected virtual void Start() { if (Mode == Modes.Start) { Parent(); } } /// /// Sets this transform's parent to the target /// public virtual void Parent() { this.transform.SetParent(TargetParent); } } }