/// <summary> /// Obtains a monobehaviour if existent else creates one, but also makes it persistent /// </summary> /// <returns>the monobehaviour</returns> private static UtilityMonoBehaviour GetPersistentMonoBehaviour() { UtilityMonoBehaviour behaviour = GetMonoBehaviour(); UnityEngine.Object.DontDestroyOnLoad(behaviour.gameObject); return(behaviour); }
/// <summary> /// Obtains a monobehaviour if existent else creates one /// </summary> /// <returns>the monobehaviour</returns> private static UtilityMonoBehaviour GetMonoBehaviour() => monoBehaviour ? monoBehaviour : monoBehaviour = new GameObject { name = "UtilityMethods_GameObject" } .AddComponent <UtilityMonoBehaviour>();