using UnityEngine; using System.Collections; public class DontDel : MonoBehaviour { public GameObject temp; private static bool m_IsHaveOne =false; private GameObject m_clone; void Start () { if (!m_IsHaveOne) { m_clone = Instantiate(temp) as GameObject; DontDestroyOnLoad(m_clone); m_IsHaveOne = true; } } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.W)) { Application.LoadLevel("Scene2"); } if (Input.GetKeyDown(KeyCode.Q)) { Application.LoadLevel("Scene1"); } } }
这个脚本在多个场景里面绑定多个GameObject并没有问题,貌似static是全局的,怎么切换场景也只有一个clone