- Home /
How to Delete an Object from coming Back in Game (C#)
This might sound a little bit confusing at first, but in my game I am trying to use a key system to unlock bonus levels. I have applied a Destroy() command to the key object but the keys keep coming back each time the level is reloaded (without restarting game) because it reloads the level as it was to start. Is there a way to permanently terminate an object until the game is reloaded (game stopped then played again)? Thanks for the help.
Answer by Kiwasi · Jun 28, 2014 at 02:28 AM
Check out the persistent data tutorial. Choose the appropriate technique for your game. Then store a bool on your gameObject. In Awake() you can check if the bool is true, then destroy the object.
Alternatively you could only create the object if the bool is true. Up to you.
Thanks for the help. I just started learning C# not too long ago so sorry if the question was dumb. Thanks again!
Saving data in unity is tricky. Let me know if you have any problems once your script is written.
Your answer
![](https://koobas.hobune.stream/wayback/20220613152701im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Multiple Cars not working 1 Answer
Player lives script help 1 Answer