Answers for "unity c# static monobehaviour"

C#
0

unity c# static monobehaviour

using UnityEngine;

    public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
    {
        public static T instance
        {
            get
            {
                if (_instance == null)
                    _instance = FindObjectOfType<T>();
                return _instance;
            }
        }
        static T _instance;
        public static bool instanceExists
        {
            get { return instance != null; }
        }
        protected virtual void OnDestroy()
        {
            if (instance == this)
            {
                _instance = null;
            }
        }
    }
    
//Also first part of this video:
//https://www.youtube.com/watch?v=hQE8lQk9ikE
Posted by: Guest on November-03-2020

C# Answers by Framework

Browse Popular Code Answers by Language