Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement