You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
2 months ago
|
using UnityEngine;
|
||
|
|
||
|
public abstract class Ability : ScriptableObject
|
||
|
{
|
||
|
[Header("Ability Settings")]
|
||
|
public string abilityName;
|
||
|
public string abilityKey;
|
||
|
public KeyCode keybind; // Key to activate the ability
|
||
|
public float cooldownTime; // Cooldown duration in seconds
|
||
|
|
||
|
private float lastActivationTime;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Checks if the ability can be activated (e.g., not on cooldown).
|
||
|
/// </summary>
|
||
|
public bool CanActivate()
|
||
|
{
|
||
|
return Time.time >= lastActivationTime + cooldownTime;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Invokes the ability.
|
||
|
/// </summary>
|
||
|
/// <param name="owner">The GameObject or player triggering this ability.</param>
|
||
|
public void TryActivate(GameObject owner)
|
||
|
{
|
||
|
if (CanActivate())
|
||
|
{
|
||
|
Activate(owner);
|
||
|
lastActivationTime = Time.time;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log($"{abilityName} is on cooldown.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected abstract void Activate(GameObject owner); // Logic for the specific ability
|
||
|
}
|