unity->C#简单的单例模式
using UnityEngine;
using System.Collections;public class c1 {
public static c1 aaa;
public int bbb;
private c1()
{
}
public static c1 instance()
{
if(aaa == null){
aaa=new c1 ();
}
return aaa;
}
}
-----------------------------
using UnityEngine;
using System.Collections;
public class c2 : MonoBehaviour {
public c1 gh=c1.instance();
void Start () {
gh.bbb = 101;
}
void Update () {
Debug.Log (gh.bbb);
}
}
------------------------------
using UnityEngine;
using System.Collections;
public class c3 : MonoBehaviour {
public c1 gk=c1.instance();
void Start () {
gk.bbb = 123;
}
void Update () {
Debug.Log (gk.bbb);
}
}