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. 125204-bandicam-2018-09-26-08-04-13-885.jpg

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!

Your code looks like it should work to me.

Try attaching Visual Studio to Unity:

And then set a breakpoint on your Destroy line :

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.