Files
beyond/Assets/Scripts/Characters/Skills/ProjectileSpell.cs
2026-01-19 14:25:38 +01:00

46 lines
1.6 KiB
C#

using System.Collections;
using UnityEngine;
using Invector;
namespace Beyond
{
[CreateAssetMenu(menuName = "Magic/Spells/Projectile Spell")]
public class ProjectileSpell : SpellDefinition
{
[Header("Projectile Settings")]
public GameObject projectilePrefab;
public float spawnDelay = 0.2f; // Sync with animation hand throw
public float lifeTime = 5f;
public float aimHeightOffset = 1.0f;
public override void Cast(MagicAttacks caster, Transform target)
{
caster.StartCoroutine(CastRoutine(caster, target));
}
private IEnumerator CastRoutine(MagicAttacks caster, Transform target)
{
// 1. Rotate
yield return caster.RotateTowardsTargetRoutine(target, rotationDuration);
// 2. Wait for animation point
yield return new WaitForSeconds(Mathf.Max(0, spawnDelay - rotationDuration));
// 3. Spawn
Vector3 spawnPos = caster.transform.position + caster.transform.forward + Vector3.up * 1.5f;
GameObject obj = Instantiate(projectilePrefab, spawnPos, caster.transform.rotation);
// 4. Aim
if (target != null)
{
Vector3 aimDir = (target.position + Vector3.up * aimHeightOffset) - spawnPos;
obj.transform.rotation = Quaternion.LookRotation(aimDir);
}
// 5. Apply Modifiers
caster.ApplyDamageModifiers(obj);
Destroy(obj, lifeTime);
}
}
}