【问题标题】:Hide game object in other scenes in Unity在 Unity 中隐藏其他场景中的游戏对象
【发布时间】: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,您的问题解决了吗?

标签: c# unity3d


【解决方案1】:

你可以尝试做这样的事情:

m_Scene = SceneManager.GetActiveScene();
sceneName = m_Scene.name;
//Do logic by checking the specific scene you want
if (sceneName == YOUR_SCENE) {
    this.gameObject.SetActive(false);  //Set false to hide, true to show

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2022-10-18
    相关资源
    最近更新 更多