Unity Singleton Code

后端 未结 4 1936
逝去的感伤
逝去的感伤 2020-12-03 04:48

I\'m new to Unity and am trying to write some Unity logic which initialises and register/resolves a singleton instance of the Email object so that it can be used across seve

4条回答
  •  醉梦人生
    2020-12-03 05:13

    You can, for example, use this code:

    public class example : MonoBehaviour
    {
        public static example instance;
    
        public void Start()
        {
            (!instance)
                instance = this;
        }
    }
    

提交回复
热议问题