How do I allow my function to run only once at a time?

So in my program I have a button that when I press will generate a series of random numbers and output it into the UI. I got my random number generator working but I could not figure out a way to not let the the function run only one at a time.

I need it so that when I press the button (Roll()), the button will not be interactable for the time the numbers are being generated, then when the function finishes performing, the button becomes interactable again.

The problem for me now is I don’t know while my while statement is not making the button not interactable and so I can press my button many times and the function will just run multiple times at a time cause lots of random numbers to be displayed which is what I don’t want.

Thank you for any help in advance.

private int RanNum;
private bool Rolling = false;

public Text RolledNum;
public Text HasBeenRolled;
public Transform RollButton;

void Start () {
	RollButton.GetComponent<Button> ().interactable = true;

void NumRoll(){
	RanNum = Random.Range (1, 15);
	RolledNum.text = RanNum.ToString ();

void RepeatRoll(){
	InvokeRepeating ("NumRoll", 0, 0.3f);
	Rolling = true;
	while (Rolling == true) {
		RollButton.GetComponent<Button> ().interactable = false;

public void Roll(){
	RepeatRoll ();

You could use a coroutine and let it run in a while(true) loop until you have rolled all the numbers, or then just put a simple timer function on the button like so (untested code, but you get the gist):

public void ButtonPressed () {
    button.interactable = false;
    Invoke("ReActivateButton", 2);

public void ReActivateButton () {
     button.interactable = true;