How to disable a button (lifeline) after it has been clicked/used?

Hi everyone, I am rather new to the Unity community and Unity itself having only 2 months of experience. Nevertheless, I am creating a game similar to Millionaire (which is basically a quiz) in which ‘lifelines’ can be utilized to help the player answer the questions he/she is not sure of. Out of 3 lifelines I managed to make 2 but I ran into a slight hiccup. In the game show itself the lifelines can only be used once for all the questions. Does anyone have a suggestion for a code that could disable the lifeline after it has been used?

You need to do two things. Firstly, the Button script:

using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
    public void ButPress(Button button)
        button.interactable = false;

You can use the button property “Interactable” to make it not clickable. You’ll see that the script has a parameter of type Button. When we link to the button in the Inspector, we have to pass the button itself as a parameter. That means that the Button event looks like this:


You now have three fields to fill in. the one under “Runtime Only” is the game object that contains the button script. I’ve created a separate game object called UI Manager. The second field, to the right of “Runtime Only” is the name of the public method that you want to call. You can see from my script that it’s called “ButPress”. The third field, just below the second needs to have the button itself. Drag the button from the Hierarchy into this field.

You can also set the colour of a non-interactable button - in the inspector, change the “Disabled Color”. However, it is faded out so you don’t have to change the colour if you don’t want to. Let us know if you have any problems.

@SurreyMuso I tried what you suggested but that only disables my button, I want it so that it first does its function and only then becomes disabled.