Exemplo n.º 1
0
    void Detonate()
    {
        Vector3 explosionPosition = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPosition, radius);
        // get all the rigid bodies around
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();
            if (rb != null)
            {
                // deteach them if needed so they can fly around
                hit.transform.parent = null;
                // apply explosion force
                rb.AddExplosionForce(power, explosionPosition, radius, 3.0F);
            }
            // also apply delayed damage
            DamageableEntity entity = hit.GetComponent <DamageableEntity>();
            if (entity != null)
            {
                // check if they die instantly
                bool noDelay = hit.CompareTag("Player") || hit.CompareTag("Instant Death");
                entity.OnDamage(gameObject, damage, noDelay ? 0 : onDeathDelay);
            }
        }
        // destroy bomb too
        Destroy(gameObject);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Do damage on the hit entity every X seconds (damage rate)
 /// </summary>
 private void DoDamage()
 {
     if (target)
     {
         target.OnDamage(gameObject, damage);
         // call it again
         Invoke("DoDamage", damageRate);
     }
 }
Exemplo n.º 3
0
 public void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Enemy"))
     {
         DamageableEntity damageableEntity = other.gameObject.GetComponent <DamageableEntity>();
         if (damageableEntity)
         {
             damageableEntity.OnDamage(gameObject, damage);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Does damage to the given object only if the component is enabled
 /// and the object is one of the targets of this component.
 /// </summary>
 /// <param name="obj">Object to apply damage to.</param>
 /// <returns>True if the object received any damage.</returns>
 protected bool DoDamage(GameObject obj)
 {
     // First check if the object's layer corresponds to the targetLayerMask
     if (isActive && IsEntityTarget(obj))
     {
         // maybe do othe checks here later
         // check if the object is damagable
         DamageableEntity entity = obj.GetComponent <DamageableEntity>();
         if (entity)
         {
             return(entity.OnDamage(gameObject, damage));
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 public override bool OnDamage(GameObject origin, float damage, float delayDeath = 0)
 {
     return(shiedDamageableEntity.OnDamage(origin, damage, delayDeath));
 }