예제 #1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        // Check if incoming gameObject is a PlayerShot (has a PlayerShot component).
        PlayerShot shot = collider.gameObject.GetComponent <PlayerShot> ();

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