【发布时间】:2020-02-08 19:17:57
【问题描述】:
我已使用此代码停止破坏特定游戏对象。问题是当我将包含此对象的场景更改为另一个不同的场景时,即使在不同的场景中游戏对象仍然显示... 如何仅在其场景中显示游戏对象。 我希望我清楚地说明我的问题。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DontDestroy : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(this.gameObject);
if(FindObjectsOfType(GetType()).Length > 1) {
Destroy(gameObject);
}
}
}
【问题讨论】:
-
在设计时不要在每个场景中都放置对象的副本,而是创建一个预加载场景,您只加载一次,其中包含所有您不会破坏的加载对象。在 unityfourms forum.unity.com/threads/… 中查看此帖子
-
@adelkanso,您的问题解决了吗?