Delay Button Press

Quick question - I’d like to use a button to instantiate a prefab, but I don’t want to have collider issues if the person presses the button a lot of times, quickly.

I’d therefore like to delay the button a bit to allow the object to clear the spawn area, however I tried adding a yield and disabling the button, but the event trigger I have on the button still functions even though the button is disabled… strangely.

Any suggestions? Thanks.

Easiest thing to do:

private float lastPressedButton = -9999f;
public float interval = 1f;

void Update() {
if (Input.GetButtonDown("SpawnButton") && Time.time > lastPressedButton + interval) {
DoTheThing();
lastPressedButton = Time.time;
}
}

If you’re referring to a UI button, you can add that time check to the button function itself.

Great thanks, would you mind a bit more info as to 'add to the UI button itself", do you mean in the event trigger script, for what the button does? That would put it in the say “move left” button, instead of the update, if I add to the update not sure how I’ll add it to the button! :-/