Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class SceneObject<TSelf> : MonoBehaviour where TSelf : MonoBehaviour
- {
- public static TSelf Current { get; private set; }
- protected virtual void OnEnable()
- {
- if (Current != null)
- {
- Debug.LogErrorFormat("There should never be more than 1 scene object '{0}'!", typeof(TSelf));
- return;
- }
- Current = GetComponent<TSelf>();
- }
- protected virtual void OnDisable()
- {
- Current = null;
- }
- }
Add Comment
Please, Sign In to add comment