Exemplo n.º 1
0
 void OnTriggerEnter(Collider other)
 {
     if (canExplose)
     {
         if (layerMask.ContainsLayer(other.gameObject.layer))
         {
             Debug.Log("Detect");
             if (impactEffect)
             {
                 GameObject goEffect = Instantiate(impactEffect, transform.position, Quaternion.identity);
                 Destroy(goEffect, 2f);
                 Collider[] hitColliders = Physics.OverlapSphere(transform.position, exploseRadius, layerMask);
                 foreach (Collider col in hitColliders)
                 {
                     GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                     if (health && dealDamages)
                     {
                         //Debug.Log( col.gameObject.name + Damages);
                         health.TakeDamage(damages, this.gameObject);
                     }
                 }
                 Destroy(gameObject, .1f);
             }
         }
     }
 }
Exemplo n.º 2
0
    void OnTriggerEnter(Collider collision)
    {
        GenericHealth health = collision.gameObject.GetComponent <GenericHealth>();

        if (health)
        {
            health.TakeDamage(enemyAttack.attackDamages, gameObject);
        }
    }
Exemplo n.º 3
0
    void OnCollisionEnter(Collision collider)
    {
        if (collisionMask.ContainsLayer(collider.gameObject.layer))
        {
            Vector3 impactPosition = transform.position;
            if (impactEffect)
            {
                if (impactOnFloor)
                {
                    impactPosition.y = collider.transform.position.y; //TODO Improve height calculation
                }
                GameObject goEffect = Instantiate(impactEffect, impactPosition, Quaternion.identity);
                Destroy(goEffect, 2f);
            }
            if (exploseProjetcile)
            {
                Collider[] hitColliders = Physics.OverlapSphere(impactPosition, exploseRadius, collisionMask);
                foreach (Collider col in hitColliders)
                {
                    GenericHealth health = col.gameObject.GetComponent <GenericHealth>();
                    if (health && dealDamages)
                    {
                        //Debug.Log( col.gameObject.name + Damages);
                        health.TakeDamage(damages, this.gameObject);
                    }
                }
                Destroy(gameObject, .1f);
            }

            GenericHealth genericHealth = collider.gameObject.GetComponent <GenericHealth>();
            if (genericHealth && dealDamages)
            {
                genericHealth.TakeDamage(damages, this.gameObject);
                Destroy(gameObject);
            }
        }
    }