Guest User

Untitled

a guest
Oct 11th, 2020
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class SceneObject<TSelf> : MonoBehaviour where TSelf : MonoBehaviour
  4. {
  5.     public static TSelf Current { get; private set; }
  6.  
  7.     protected virtual void OnEnable()
  8.     {
  9.         if (Current != null)
  10.         {
  11.             Debug.LogErrorFormat("There should never be more than 1 scene object '{0}'!", typeof(TSelf));
  12.             return;
  13.         }
  14.         Current = GetComponent<TSelf>();
  15.     }
  16.     protected virtual void OnDisable()
  17.     {
  18.         Current = null;
  19.     }
  20. }
RAW Paste Data