private void Start()
 {
     if (target == null)
     {
         transform.LookAt(transform.position + instigator.transform.forward);
     }
     else
     {
         transform.LookAt(target.GetHitLocation());
     }
     Destroy(this.gameObject, maxLifetime);
 }
예제 #2
0
 public void OnHit(Health target)
 {
     onHit.Invoke();
     if (hitEffect != null)
     {
         Instantiate(hitEffect, target.GetHitLocation(), target.transform.rotation);
     }
 }
 private void OnTriggerEnter(Collider other)
 {
     if (target != null)
     {
         // Enemy AI
         if (other.GetComponent <Health>() != target)
         {
             return;
         }
         if (target.IsDead())
         {
             return;
         }
         target.TakeDamage(instigator, damage);
         if (hitEffect != null)
         {
             Instantiate(hitEffect, target.GetHitLocation(), transform.rotation);
         }
     }
     else
     {
         // Player
         Health hitCharacter = other.GetComponent <Health>();
         if (hitCharacter == null || hitCharacter.IsDead() || hitCharacter.GetComponent <CombatTarget>() == null)
         {
             return;
         }
         hitCharacter.TakeDamage(instigator, damage);
         if (hitEffect != null)
         {
             Instantiate(hitEffect, hitCharacter.GetHitLocation(), transform.rotation);
         }
     }
     onHit.Invoke();
     speed = 0f;
     foreach (GameObject toDestroy in destroyOnHit)
     {
         Destroy(toDestroy);
     }
     Destroy(this.gameObject, lifeAfterImpact);
 }