简体   繁体   English

加载新场景时如何删除这些游戏对象?

[英]How can I remove these game objects when loading a new scene?

I am trying to create an augmented reality quiz game. 我正在尝试创建增强现实问答游戏。 However, I have a problem when I finish one quiz. 但是,当我完成一个测验时,我有一个问题。 The Data controller which contains the questions isn't being destroyed properly after ending the quiz. 结束测验后,包含问题的数据控制器未正确销毁。 It just adds up to the hierarchy. 它只是构成了层次结构。

By the way, I followed the Quiz Game tutorial from Unity. 顺便说一下,我遵循了Unity的Quiz Game教程。

public void EndRound () {


    isRoundActive = false;
    questionDisplay.SetActive (false);
    roundEndDisplay.SetActive (true);
    DestroyObject (FindObjectOfType<DataController> ());

}

How can I destroy the game object completely? 如何完全销毁游戏对象? So when I return to menu it will no longer add up and be part of the next quiz which will be selected. 因此,当我返回菜单时,它将不再累加并成为将要选择的下一个测验的一部分。 Thank you. 谢谢。

This: 这个:

DestroyObject (FindObjectOfType<DataController> ());

will only destroy the component DataController . 只会破坏组件DataController To destroy the game object tree you can write: 要销毁游戏对象树,您可以编写:

DestroyObject (FindObjectOfType<DataController>().gameObject);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将多场景游戏转换为单场景游戏? - How can i convert a game with multiple scene into a single scene game? 重新加载游戏场景时,对象不会统一加载 - When I reload my game scene the objects do not reload in unity 如何将我的分数游戏 Object 从我的游戏场景转移到 Unity 中的游戏结束场景 - How can I Transfer my Score Game Object from my game scene to game over scene in Unity 按下按钮时如何使新场景淡入? - How can I make a new scene fade in when a button is pressed? 为什么在重新加载游戏场景时开始新游戏时它还会记住一个标志状态为真? - Why when making start a new game when it's loading the game scene over again it also remember one flag state as true? 加载新场景时屏幕闪烁 - Screen flashes when loading new scene 在重新加载场景时,如何使我的Singleton MonoBehaviour类的实例以新的方式启动? - How can I make my instance of a Singleton MonoBehaviour class start as new when reloading the scene? 当我按下游戏场景上的按钮时,它开始游戏 - When i press button on the game scene its starts the game 如何使用 range 属性添加更多新的实例化对象或删除对象? - How can I use the range attribute to add more new instantiated objects or to remove objects? 我如何将我的球员得分保留到新的场景? - how can i retain my player score to a new scene?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM