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.
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
. To destroy the game object tree you can write:
DestroyObject (FindObjectOfType<DataController>().gameObject);