WalkingSnail

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

public class DontDestroyOnLoad : MonoBehaviour {

//加载场景时不销毁的物体
public GameObject[] DontDestroyObjects;

//是否已经存在DontDestroy的物体
private static bool isExist;

//-------------------------------------------------------------------------------

void Awake()
{
if (!isExist)
{
for (int i = 0; i < DontDestroyObjects.Length; i++)
{
//如果第一次加载,将这些物体设为DontDestroy
DontDestroyOnLoad(DontDestroyObjects[i]);
}

isExist = true;
}
else
{
for (int i = 0; i < DontDestroyObjects.Length; i++)
{
//如果已经存在,则删除重复的物体
Destroy(DontDestroyObjects[i]);
}
}
}

//-------------------------------------------------------------------------------
}

分类:

技术点:

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-12-10
  • 2021-12-04
  • 2021-12-26
猜你喜欢
  • 2022-01-24
  • 2022-12-23
  • 2022-01-23
  • 2022-01-13
  • 2021-11-16
  • 2021-11-28
  • 2022-02-04
相关资源
相似解决方案