[SOLVED] How do I Disable a Button Upon Press?

So I’m using a UI button and I’ve tried using this to disable it after it is pressed but it disables the image for the button and not the actual script for the image. I want the image to remain, but the button to no longer be able to be pressed.

I’ve never known how to call the new UI system using GetComponent. How can I do this?

Any help would be greatly appreciated!

– Chris

Hey, what I would do in your case is give the button a tag such as “Play”, then you create a script with a public method called “DisableButton”. Now you can get the button’s component and you want to toggle the “Interactable” property. Attach the script the the canvas and have the button be a child of the canvas. Then on the button component in the inspector add an “Onclick” event then drag the canvas as the game object and then navigate to your script and select the “DisbaleButton” (or whatever you called the method ) method. Here is what the method would look like:

public void DisableButton()
{
    Button btn = GameObject.FindGameObjectWithTag("Play").GetComponent<Button>();
    btn.Interactable = false;
}

Hope this helps

-Joshmond

1 Like

Thanks, that helped a lot!