Activate/deactivate object with UI buttons

Hi everyone,

I am trying to activate/deactivate objects with UI buttons (the one with canvas)

I tried a few scripts I found on Unity tutorial but the objects just disappear without clicking the button

I want the object to disappear or appear ONLY when I click the UI button.

I don’t have a programming background, so I highly appreciate if anyone can give me a simple answer. Thanks a lot.

  1. Make an UI Button by going to “Create” - “UI”- “Button”
  2. This will create a Canvas and Events System (if the scene doesn’t have one already)
  3. Make an empty GameObject (not UI)
  4. Attach a new script to the new GameObject
  5. Go back to the button inspector and scroll all the way down to "Button(Script)
  6. In a grayish box section labeled “OnClick”, click the little circular button and it will give you a list to select from
  7. From that list, select the new GameObject you created earlier.
  8. Now by editing the script on the new GameObject, and afterwards selecting that function from the OnClick Section, you can control what the button does when clicked.