unity 不销毁物体,全局唯一性

下面插入代码

本脚本挂在你不想销毁的物体上面

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExitApp : MonoBehaviour {
    public static ExitApp instance;

    //全局唯一性  
    private void Awake()
    {
        if (instance != null)
        {
            Debug.Log("严重 : 对象已经存在!");
            DestroyImmediate(gameObject);
        }
        else
        {
            DontDestroyOnLoad(gameObject);
            instance = this;
        }
    }  
  
}

 

posted @ 2019-12-09 12:47  剑起苍穹  阅读(1190)  评论(0编辑  收藏  举报
/*鼠标点击特效*/