首页 > 技术文章 > Unity3D设计模式之单例模式

htwzl 2017-07-07 12:49 原文

 

项目开发过程中经常使用到,脚本是继承monobehavior,使用起单例来比较简单。

using UnityEngine;
using System.Collections;

public class test: MonoBehaviour {

    public static test instance;

    private void Awake()
    {
        if (ins != null)
        {
       Destroy(this.gameObject);
        }
       else
       {
        ins = this;
       }
   }

    void Update () {
 
    }

}

 

推荐阅读