daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public abstract class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
  4. {
  5.     // Instanciated version of this MonoBehaviour
  6.     public static T s_Instance { get; set; }
  7.  
  8.     protected virtual void Awake()
  9.     {
  10.         // If the Instance is already set, destroy this instance
  11.         if (s_Instance != null)
  12.             Destroy(this);
  13.         else
  14.             s_Instance = this as T;
  15.     }
  16.  
  17.     protected virtual void OnDestroy()
  18.     {
  19.         // Set the instance to null when this instance is destroyed
  20.         s_Instance = null;
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top