void Awake() { if (instance == null) { instance = this.GetComponent <WebSocketReceiver>(); } DontDestroyOnLoad(this.gameObject); }
/// <summary> /// 如果没有Receiver物体,用这个函数创建 /// </summary> public static void AutoCreateInstance() { GameObject go = GameObject.Find("/WebSocketReceiver"); if (go == null) { go = new GameObject("WebSocketReceiver"); } if (go.GetComponent <WebSocketReceiver>() == null) { go.AddComponent <WebSocketReceiver>(); } instance = go.GetComponent <WebSocketReceiver>(); }