25 lines
744 B
C#
25 lines
744 B
C#
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;
|
|
|
|
var go = Instantiate(projectilePrefab, user.CastPos(), Quaternion.LookRotation(user.Forward()));
|
|
var rb = go.GetComponent<Rigidbody>();
|
|
if (rb) rb.velocity = user.Forward() * speed;
|
|
|
|
var dmg = go.GetComponent<ProjectileDamage>();
|
|
if (!dmg) dmg = go.AddComponent<ProjectileDamage>();
|
|
dmg.damage = damage;
|
|
|
|
Destroy(go, lifeTime);
|
|
}
|
|
} |