using System.Collections; using UnityEngine; [CreateAssetMenu(menuName = "Abilities/Channel Heal")] public class ChannelHealAbility : Ability { public GameObject healPrefab; public float channelTime = 5f; // seconds to wait public float healAmount = 50f; // how much to heal public override void Activate(AbilityUser user) { if (!user) return; user.StartCoroutine(ChannelRoutine(user)); } private IEnumerator ChannelRoutine(AbilityUser user) { float elapsed = 0f; var go = Instantiate(healPrefab, user.CastPos(), Quaternion.LookRotation(user.Forward())); while (elapsed < channelTime) { // Cancel if player moves if (IsPlayerMoving()) { Debug.Log("Heal cancelled: player moved."); Destroy(go); yield break; } elapsed += Time.deltaTime; yield return null; } // Heal and spend mana on completion if (user.mana && !user.mana.Spend(manaCost)) { Debug.Log("Not enough mana to complete heal."); Destroy(go); yield break; } if (user.health) user.health.Heal(healAmount); Debug.Log($"Healed {healAmount} HP after channel."); Destroy(go); } private bool IsPlayerMoving() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); return (Mathf.Abs(h) > 0.01f || Mathf.Abs(v) > 0.01f); } }