using System.Collections.Generic; using Unity.Netcode; using UnityEngine; public class AbilitySystem : MonoBehaviour { [Header("Assigned Abilities")] public List abilities = new List(); private Ability activeAbility; // Tracks the currently active ability in "spawn mode" private bool isAbilityActive = false; void Update() { // If ability mode is active, listen for mouse input to activate ability if (isAbilityActive && Input.GetMouseButtonDown(0)) { UseActiveAbility(); ToggleAbilityMode(activeAbility); } } /// /// Activates ability by key (called externally). /// /// The key assigned to an ability. public void ActivateAbilityByKey(string key) { foreach (var ability in abilities) { if (ability.abilityKey == key) { ToggleAbilityMode(ability); return; } } Debug.LogWarning($"No ability assigned to key {key}."); } /// /// Toggles the ability activation mode. /// /// The ability to toggle. private void ToggleAbilityMode(Ability ability) { if (isAbilityActive && activeAbility == ability) { DeactivateAbilityMode(); } else { ActivateAbilityMode(ability); } } private void ActivateAbilityMode(Ability ability) { isAbilityActive = true; activeAbility = ability; Debug.Log($"Ability {ability.name} activated! Click to use."); } private void DeactivateAbilityMode() { isAbilityActive = false; activeAbility = null; Debug.Log("Ability mode deactivated."); } private void UseActiveAbility() { if (activeAbility != null) { activeAbility.TryActivate(gameObject); DeactivateAbilityMode(); // Ability used, deactivate mode } } }