Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        // Check if incoming gameObject is a PlayerShot (has a PlayerShot component).
        EnemyShot shot = collider.gameObject.GetComponent <EnemyShot> ();

        if (shot)
        {
            Debug.Log(collider.gameObject + " detected.");
            // Apply damage.
            health -= shot.GetDamage();
            AudioSource.PlayClipAtPoint(hitTakenSound, transform.position);
            Debug.Log("Player health remaining: " + health);
            // Message shot of hit.
            shot.Hit();
            // Check if damage is leathal.
            if (health <= 0)
            {
                shot.LethalHit();
                Death();
            }
        }
    }