当单例脚本直接绑定到组件上时不用new直接用this
public class PhotonEngine : MonoBehaviour {
private static PhotonEngine Instance;
private void Awake()
{
if(Instance == null)
{
Instance = this; //当脚本直接绑定到组件上时,不用new直接用this
//当前GameObject不会随场景的销毁而销毁
DontDestroyOnLoad(this.gameObject);
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}