using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class AbilityCooldownTracker : MonoBehaviour { public List abilityCooldowns = new List(); public void StartAbilityCooldown(BaseAbility ability) { AbilityCooldownEntry entry = new AbilityCooldownEntry(); entry.ability = ability; entry.cooldownCoroutine = StartCoroutine(TrackCooldown(entry, RemoveEntryOnCooldownReset)); abilityCooldowns.Add(entry); } public void RemoveEntryOnCooldownReset(AbilityCooldownEntry entryToRemove) { abilityCooldowns.Remove(entryToRemove); } public bool OnCooldown(BaseAbility ability) { for (int i = 0; i < abilityCooldowns.Count; i++) { if (abilityCooldowns[i].ability == ability) return true; } return false; } IEnumerator TrackCooldown(AbilityCooldownEntry entry, Action RemoveOnCooldownEnded) { yield return new WaitForSeconds(entry.ability.cooldown); if (RemoveOnCooldownEnded != null) RemoveOnCooldownEnded.Invoke(entry); } } public class AbilityCooldownEntry { public BaseAbility ability; public Coroutine cooldownCoroutine; }