Skip to main content
deleted 2 characters in body
Source Link
Ben
  • 517
  • 2
  • 4
  • 15

Here is another approach, using a cooldown timer that gets decremented and reset in the update method.

For this to work, you must set isPressedButton whenever your player attack button is pressed and released.

// Input state
private bool isPressedButton;

// Button cooldown
[Tooltip("Minimum time between button inputs being processed (in seconds)")]
[SerializeField] private float buttonCooldownDuration = 0.4f;
private float buttonCooldownCurrent;

// Update method
void Update()
{
    // If pressed the button, and the cooldown is over
    if (isPressedButon && buttonCooldownCurrent <= 0)
    {
        // Perform the button action...

        // Reset the button cooldown
        buttonCooldownCurrent = buttonCooldownDuration;

        // Skip the rest
        return;
    }

     // Decrement the button cooldown
     buttonCooldownCurrent -= Time.deltaTime; 

}
```

Here is another approach, using a cooldown timer that gets decremented and reset in the update method.

For this to work, you must set isPressedButton whenever your player attack button is pressed and released.

// Input state
private bool isPressedButton;

// Button cooldown
[Tooltip("Minimum time between button inputs being processed (in seconds)")]
[SerializeField] private float buttonCooldownDuration = 0.4f;
private float buttonCooldownCurrent;

// Update method
void Update()
{
   // If pressed the button, and the cooldown is over
   if (isPressedButon && buttonCooldownCurrent <= 0)
   {
      // Perform the button action...

      // Reset the button cooldown
      buttonCooldownCurrent = buttonCooldownDuration;

      // Skip the rest
      return;
   }

   // Decrement the button cooldown
   buttonCooldownCurrent -= Time.deltaTime;
}
```

Here is another approach, using a cooldown timer that gets decremented and reset in the update method.

For this to work, you must set isPressedButton whenever your player attack button is pressed and released.

// Input state
private bool isPressedButton;

// Button cooldown
[Tooltip("Minimum time between button inputs being processed (in seconds)")]
[SerializeField] private float buttonCooldownDuration = 0.4f;
private float buttonCooldownCurrent;

// Update method
void Update()
{
    // If pressed the button, and the cooldown is over
    if (isPressedButon && buttonCooldownCurrent <= 0)
    {
        // Perform the button action...

        // Reset the button cooldown
        buttonCooldownCurrent = buttonCooldownDuration;

        // Skip the rest
        return;
    }

     // Decrement the button cooldown
     buttonCooldownCurrent -= Time.deltaTime; 

}
```
Source Link
Ben
  • 517
  • 2
  • 4
  • 15

Here is another approach, using a cooldown timer that gets decremented and reset in the update method.

For this to work, you must set isPressedButton whenever your player attack button is pressed and released.

// Input state
private bool isPressedButton;

// Button cooldown
[Tooltip("Minimum time between button inputs being processed (in seconds)")]
[SerializeField] private float buttonCooldownDuration = 0.4f;
private float buttonCooldownCurrent;

// Update method
void Update()
{
   // If pressed the button, and the cooldown is over
   if (isPressedButon && buttonCooldownCurrent <= 0)
   {
      // Perform the button action...

      // Reset the button cooldown
      buttonCooldownCurrent = buttonCooldownDuration;

      // Skip the rest
      return;
   }

   // Decrement the button cooldown
   buttonCooldownCurrent -= Time.deltaTime;
}
```