I have create a GameObject called MyButton and have been able to assign a method in my script to it, so that when I click the button the method is succesfully called.
But I what I can’t figure out, is how to actually turn the button on/off.
So the GameObject itself is called MyButton (with a child called Text for the text that appears on the button).
In my script at the top I have declared the button with:
public Button MyButton;
The method that is called when the button is clicked looks like this, and I am trying to turn it off when I click it:
public void clickMyButton() {
Debug.Log ("button clicked" + "\n");
MyButton.gameObject.SetActive (false);
}
The line where I am trying to SetActive(false) is giving me this error:
NullReferenceException: Object reference not set to an instance of an object
So the button recognizes the script when clicking on it, but the script does not seem to recognize the button.
Am I missing something here that would allow the script to turn the button on/off?
Thanks