Skip to main content

Button Extras

AchButtonCooldown and AchButtonHold are additive components that extend an existing Button. Both require a Button component on the same GameObject to function.

AchButtonCooldown

Disables the button immediately after a click and re-enables it once the cooldown period has elapsed. Includes a built-in countdown label to display the remaining time.

Inspector Fields

FieldDescription
CooldownMinimum wait time in seconds between clicks. Default: 1
Show CountdownWhether to display the remaining cooldown time on a label
Countdown LabelText component to show the countdown (optional)
On Cooldown StartUnityEvent fired when the cooldown begins
On Cooldown EndUnityEvent fired when the cooldown expires

API

MemberDescription
IsCoolingDownWhether the button is currently cooling down
StartCooldown()Starts the cooldown manually. Restarts the timer if already cooling down
ResetCooldown()Cancels the cooldown immediately and re-enables the button

Usage Example

// Control the cooldown from code
var cooldown = GetComponent<AchButtonCooldown>();

// Lock the button while waiting for a server response
cooldown.StartCooldown();

// Unlock immediately once the response arrives
cooldown.ResetCooldown();

// Check availability
if (!cooldown.IsCoolingDown)
Debug.Log("Button is available");

Connect a loading spinner's activation to On Cooldown Start and its deactivation to On Cooldown End in the Inspector for visual feedback without any extra code.


AchButtonHold

Fires an event repeatedly at a fixed interval while the button is held down. Useful for continuously changing a value — such as volume or quantity — while the button is pressed.

Inspector Fields

FieldDescription
Initial DelayTime in seconds before the first repeat fires. Default: 0.5
Repeat IntervalTime in seconds between each repeat after the initial delay. Default: 0.1
On Hold FireUnityEvent invoked on each repeat

API

MemberDescription
IsHoldingWhether the button is currently being held

Usage Example

Attaching AchButtonHold to a volume increase button:

// Attach AchButtonHold to the volume + Button GameObject
// and connect On Hold Fire to the method below.

public void IncreaseVolume()
{
AudioManager.Volume = Mathf.Clamp01(AudioManager.Volume + 0.05f);
}
[Button — Volume +]
└── [AchButtonHold]
Initial Delay : 0.5
Repeat Interval : 0.1
On Hold Fire → IncreaseVolume()

After pressing and holding for 0.5 seconds, IncreaseVolume() fires every 0.1 seconds until released.


Using Both Together

AchButtonCooldown and AchButtonHold are independent and can be used on the same button.

[Button GameObject]
├── Button
├── AchButtonCooldown (2-second cooldown after click)
└── AchButtonHold (repeat fire while held)