Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Is there a way to stop objects from duplicating?

$
0
0
I have two objects, GameManager and Text, which control the game's scorekeeping and GUI text for the player respectively. I had an earlier issue where if the player went to level two, died, and restarted, GameManager and Text would duplicate. I fixed that by adding a bool `restart`, which is always set to true: public bool restart = true; if (restart) { DontDestroyOnLoad(gameObject); } I've come across a new problem, which is if the player dies on level 1 then these objects will be created again and overlap. I was wondering if there's a way to prevent this from happening, maybe by loading GameManager and Text from a script rather than having them in the inspector. I read a post that suggested instantiating both of them in a script and attaching that to an empty gameobject, but the same issue persisted along with the text not changing. Any help would be appreciated.

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>