How to add score only one time after pressed a button

I’m creating Math app and it has four answers to choose right one. it’s question change every 4s. but if player pressed answer button multiple time (ex: 4 times). the thing if it need to do is(ex; add 1 score) happen 4 times. is there any solution for that

Declare a bool such as hasPressedRightAnswer that is initially false. Inside AddScore method, first check the bool to be false, then add score if it is.Next line inside method, you should change the bool value to true. Also you should change it back to false exactly when the next question appears.
Alternatively, in your script, you can simply uncheck “Interactable” property of the button when the the right answer is pressed. then check it when new question appears.

    public class YourClassName
    {
        private bool hasPressedrightAnswer = false;
        private int score;
        private void AddScore()
        {
            if (hasPressedrightAnswer == true)
            {
                return;
            }
            ++score;
            hasPressedrightAnswer = true;
        }
        // And when the next question appears, do this in some method:
        hasPressedrightAnswer = true;
    
    
        // Alternatively
        [SerializeField] Button btn;
        private void AddScore()
        {
            ++score;
            btn.interactable = false;
        }
        // And when the next question appears, do this in some method:
        btn.interactable = true;
    }

@V_0_1_D_ thanks for your reply.



extra knowledge for me,


i have four button and i make for functions(change pressedID) for them to tell what happend when pressed. it’s work. all four fuctions are same. just change the ID number. but is there any way to use one function for all 4 buttons. for 4 buttons it’s okay, but what if i have 50 buttons. is this the way or have any solution.