39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Abilities/Freeze Shard")]
|
|
public class FreezeShardAbility : Ability
|
|
{
|
|
public GameObject projectilePrefab;
|
|
public float speed = 20f;
|
|
public float damage = 0f; // optional direct damage
|
|
public float freezeDuration = 3f;
|
|
public float lifeTime = 4f;
|
|
public float spawnOffset = 0.5f;
|
|
|
|
public override void Activate(AbilityUser user)
|
|
{
|
|
if (!user || !projectilePrefab) return;
|
|
|
|
var pos = user.CastPos() + user.Forward() * spawnOffset;
|
|
var rot = Quaternion.LookRotation(user.Forward());
|
|
var go = Instantiate(projectilePrefab, pos, rot);
|
|
|
|
var rb = go.GetComponent<Rigidbody>();
|
|
if (rb) rb.velocity = user.Forward() * speed;
|
|
|
|
var shard = go.GetComponent<FreezeShardProjectile>();
|
|
if (!shard) shard = go.AddComponent<FreezeShardProjectile>();
|
|
shard.damage = damage;
|
|
shard.freezeDuration = freezeDuration;
|
|
shard.ownerRoot = user.transform;
|
|
|
|
var projCol = go.GetComponent<Collider>();
|
|
if (projCol)
|
|
{
|
|
foreach (var oc in user.GetComponentsInChildren<Collider>())
|
|
Physics.IgnoreCollision(projCol, oc, true);
|
|
}
|
|
|
|
Destroy(go, lifeTime);
|
|
}
|
|
} |