You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Shield.cs

34 lines
656 B
C#

1 month ago
using D2D;
using D2D.Gameplay;
using UnityEngine;
public class Shield : Unit, IHittable
{
private Rigidbody[] rb;
private Health health;
private void Awake()
{
rb = ChildrenGets<Rigidbody>();
health = Get<Health>();
transform.parent.GetComponentInParent<Health>().Died += DestroyShield;
Get<Health>().Died += DestroyShield;
}
public void GetHit(float damage)
{
health.ApplyDamage(null, damage);
}
private void DestroyShield()
{
foreach (var rigid in rb)
{
rigid.isKinematic = false;
}
Get<Collider>().enabled = false;
}
}