Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //If enemy touches an apple, it steals it
        if (other.CompareTag("Apple"))
        {
            haveApple = true;
            speed     = escapingSpeed;
            appleArt.SetActive(true);
            appleStack = other.gameObject.transform.parent.GetComponent <AppleStack>();
            appleStack.RemoveApple();
        }

        //If enemy reaches the left border with an apple, this enemy is destroyed, and the apple won't return to the stack
        if (other.CompareTag("End"))
        {
            if (haveApple)
            {
                haveApple = false;
                Destroy(gameObject);
            }
        }

        //If enemy collides with a bullet, it loses health
        if (other.CompareTag("Bullet"))
        {
            SoundManager.instance.PlayHitEnemySFX();
            RemoveHealth();
            Destroy(other.gameObject);
        }

        //If enemy touches the right border, the game ends
        if (other.CompareTag("GameOver"))
        {
            SceneController.instance.InsectGameOver();
        }
    }