Exemple #1
0
    void OnTriggerEnter(Collider other)
    {
        ReactiveTarget RT = other.gameObject.GetComponent <ReactiveTarget>();

        if (RT != null)
        {
            RT.TakeDamage(damage);
        }
    }
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.name != "Barel" && other.gameObject.tag != "Player")
     {
         Vector3    explosionPos = transform.position;
         Collider[] colliders    = Physics.OverlapSphere(explosionPos, radius);
         foreach (Collider hit in colliders)
         {
             Rigidbody rb = hit.GetComponent <Rigidbody> ();
             if (rb != null)
             {
                 rb.AddExplosionForce(power, explosionPos, radius, 1f, ForceMode.Impulse);
                 ReactiveTarget target = hit.GetComponent <ReactiveTarget> ();
                 if (target != null)
                 {
                     target.TakeDamage(damage);
                 }
             }
             Destroy(gameObject);
         }
     }
 }