0
\$\begingroup\$

I have a canvas with two buttons in it and I want to enable it on the button click, but when I try to enable it, it doesn't work. However, when I try to disable it on button click it does work. Here is my code:

 public GameObject mycanvas;
  public  void onClick() {
     mycanvas.SetActive(true);
}

Can someone please tell me what I am doing wrong?

\$\endgroup\$
1
\$\begingroup\$

If the enable button is a child of the canvas, and the canvas is disabled, the button is disabled too, so you can't click it.

Moreover, are you using the On Click () callback of the Button itself, by feeding it your OnClick method? I mean something like this:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I created a blank gameObject and assigned script to it and used in the place of "Button (1) (ButtonDisable) \$\endgroup\$ – Hemlata Jan 20 '18 at 13:10
  • \$\begingroup\$ yeah I disabled the canvas. Then how should I make it work? \$\endgroup\$ – Hemlata Jan 20 '18 at 13:10
  • \$\begingroup\$ @Hemlata Use more than one canvas (or disable only the child object(s) you want to hide, rather than everything). \$\endgroup\$ – Draco18s Mar 16 '18 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.