首页 > 其他 > 详细

u3d DontDestroyOnLoad多场景问题

时间:2014-10-15 13:39:58      阅读:257      评论:0      收藏:0      [点我收藏+]
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

u3d DontDestroyOnLoad多场景问题

原文:http://www.cnblogs.com/dragon2012/p/4026018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!