首页 > 编程语言 > 详细

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

时间:2019-12-09 14:05:33      阅读:135      评论:0      收藏:0      [点我收藏+]

下面插入代码

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

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;
        }
    }  
  
}

 

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

原文:https://www.cnblogs.com/qq2351194611/p/12010364.html

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