I can't destroy my instantiated game object
This has to be a simple fix but I've spent the last 2 days looking for a solution online and couldn't find anything that worked. Pretty much all I want to do is click a button to open a menu, and click a button to close the menu.
When I clicked on the "Learn More" button the menu pops up like shown. However when I click the red x the menu is not closing. This is my script.
I know the code is being called because I put the debug.log in there to see. I also know the menu is destroyable because if I put the Destroy(menu1, 1f) in the method LoadMenu1() it gets destroyed. I know the issue has to do with the ExitMenu1() method not being able to correctly identify the object to be destroyed, but I don't know how to fix it. Please help!
Answer by v-ercart · Oct 03, 2018 at 07:33 PM
Your code looks like it should work to me.
Try attaching Visual Studio to Unity: https://docs.microsoft.com/en-us/visualstudio/cross-platform/using-visual-studio-tools-for-unity?view=vs-2017#unity-debugging
And then set a breakpoint on your Destroy line : https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2017
When Visual Studio pauses on that line, mouse over menu1 and it will show you what the value of that variable is. If it's null, it means it's not set to something. Or maybe it gets set to the wrong thing elsewhere in your code, and some other object is getting destroyed. That will be a clue toward finding the problem.
Your answer
Follow this Question
Related Questions
Destroy Instantiate is not working 0 Answers
Instantiated bullet wont destroy 1 Answer
if the ball hits the coin the coin need to be destoyed but how? i have this but it does not work. 2 Answers
Why is this object not destroying itself? 0 Answers
Information about when it is destroyed any GameObject on scene. 0 Answers