赞
踩
unity加载场景不删除模型和删除重复模型
不删除重复模型代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DontDestroy : MonoBehaviour
{
void Start()
{
DontDestroyOnLoad(gameObject);
}
}
删除重复模型代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class single : MonoBehaviour
{
private static single instance = null;//先设置一个静态变量
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else if (this != instance)
{
Destroy(gameObject);
return;
}
}
}
该脚本直接拖到3d物体上就可以了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。