示例#1
0
    public void OnHit(LocalEventNotifier.Event localEvent)
    {
        GameObject hit = ((HitEvent)localEvent).Hit;

        if (((1 << hit.layer) & this.DamagableLayers) != 0 && !_alreadyHitThisUpdate.Contains(hit))
        {
            Damagable damagable = hit.GetComponent <Damagable>();
            if (damagable != null && !damagable.Invincible)
            {
                damagable.ReceiveDamage(this);
                this.ApplyDamage(damagable);
            }
        }
    }
 protected virtual bool Hit(RaycastHit hitInfo) {
     Damagable damagable = hitInfo.collider.GetComponentInParent<Damagable>();
     if (damagable != null) {
         if (damagable.GetTeam() == team) {
             return false;
         }
         if (damage > 0) {
             damagable.ReceiveDamage(new Damage(damage, damageType));
         }
     }
     OnHit?.Invoke(damagable);
     if (hitEffect != null) {
         GameObject newEffect = Instantiate(hitEffect);
         newEffect.transform.position = hitInfo.point - velocity.normalized * 0.02f;
         newEffect.transform.rotation = Quaternion.FromToRotation(Vector3.forward, hitInfo.normal);
     }
     Destroy(gameObject);
     return true;
 }
示例#3
0
    public void OnCollide(LocalEventNotifier.Event localEvent)
    {
        CollisionEvent collision = localEvent as CollisionEvent;

        foreach (GameObject hit in collision.Hits)
        {
            if (this.CollisionWeaponType != null && this.CollisionWeaponType.SpecialEffect == WeaponType.SPECIAL_EXPLOSION && ((1 << hit.layer) & this.GetComponent <Damager>().DamagableLayers) != 0)
            {
                // Explode on impact
                Damagable damagable = this.GetComponent <Damagable>();
                while (damagable.Health > 0)
                {
                    damagable.ReceiveDamage(this.GetComponent <Damager>());
                }
            }
            else if (((1 << hit.layer) & this.BounceLayerMask) != 0)
            {
                _actor.Bounce(hit, collision.VelocityAtHit, collision.VelocityApplied, this.BounceLayerMask, 0.0f);
                break;
            }
        }
    }