项目开发过程中经常使用到,脚本是继承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 () { } }