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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-29
  • 2021-05-30
  • 2022-01-01
猜你喜欢
  • 2021-04-21
  • 2022-01-14
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
相关资源
相似解决方案