28 lines
883 B
C#
Raw Normal View History

2025-08-12 12:39:09 +05:00
using UnityEngine;
[CreateAssetMenu(menuName = "Abilities/Fireball")]
public class FireballAbility : Ability
{
public GameObject projectilePrefab;
public float speed = 22f;
public float damage = 20f;
public float lifeTime = 4f;
public override void Activate(AbilityUser user)
{
if (!user || !projectilePrefab) return;
Vector3 dir = Camera.main.transform.forward;
//var go = Instantiate(projectilePrefab, user.CastPos(), Quaternion.LookRotation(user.Forward()));
var go = Instantiate(projectilePrefab, user.CastPos(), Quaternion.LookRotation(dir));
2025-08-12 12:39:09 +05:00
var rb = go.GetComponent<Rigidbody>();
if (rb) rb.velocity = dir * speed;
2025-08-12 12:39:09 +05:00
var dmg = go.GetComponent<ProjectileDamage>();
if (!dmg) dmg = go.AddComponent<ProjectileDamage>();
dmg.damage = damage;
Destroy(go, lifeTime);
}
}