Exemplo n.º 1
0
    /*
     * handles player interacting with in-game objects
     */

    private void OnCollisionEnter2D(Collision2D collider)

    //the one with 2D on the end is for 2D, the unmarked one is for 3D objects
    //if we get an obstacle is tagged, and thats waht we get, we return true
    {
        //encountering an obstacle
        if (collider.gameObject.CompareTag("obstacle"))
        {
            Debug.Log("Collision with obstacle!");
            //SetActive takes a boolean
            //make the obstacle you touched dissapear
            collider.gameObject.SetActive(false);
        }

        //encountering a health boost
        if (collider.gameObject.CompareTag("buff"))
        {
            Debug.Log("health boosted!");
            //make the health increase item dissapear
            collider.gameObject.SetActive(false);

            //actually like boost your health
            Level.buffs += 1;
        }

        //encountering a health hazard
        if (collider.gameObject.CompareTag("nerf"))
        {
            Debug.Log("ouch");

            if (Level.buffs > 0)
            {
                //restart the level
                LoadNext.Reload();
            }
            else
            {
                //restart the game
                Level.level = 1;
                LoadNext.Restart();
            }
        }

        //encountering a level ending marker
        if (collider.gameObject.CompareTag("checkpoint"))
        {
            Debug.Log("load");
            //if finish is true, next frame will load
            //the next level
            finish = true;
        }
    }
Exemplo n.º 2
0
    //handle encounters with triggers
    private void OnTriggerStay2D(Collider2D collision)
    {
        //collision with first raincloud
        if (collision.gameObject.CompareTag("waterEnd"))
        {
            //jump back to level 4
            Level.level = 4;
            LoadNext.Reload();
        }

        //collision with second cloud
        if (collision.gameObject.CompareTag("GameController"))
        {
            //jump to level 5
            Level.level = 5;
            LoadNext.Reload();
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        /*
         * check if you're far enough along to laod another part of the level
         */
        if (Level.level > 3)
        {
            Level.LoadSection();
        }

        /*
         * if you've encountered a level end marker,
         * load the next level
         */
        if (finish == true)
        {
            finish = false;
            Debug.Log("loading");
            LoadNext.Continue();
        }

        /*
         * if you fell offscreen,
         * restart the level
         */
        if (GameObject.Find("Body").transform.position.y < -5)
        {
            Debug.Log("you fell :(");
            if (Level.level <= 5 && Level.buffs > 0)
            {
                Level.buffs -= 1;
                LoadNext.Reload();
                Debug.Log("health subtracted");
            }
            else
            {
                Level.level = 1;
                LoadNext.Restart();
            }
        }

        /*
         * if you exit stage right on the last level,
         * return to menu screen
         * and be prepared to run the game again
         */
        if (GameObject.Find("Body").transform.position.x > 8 && Level.level >= 6)
        {
            Debug.Log(Level.level);
            Level.level = 1;
            LoadNext.Restart();
        }

        /*
         * load the secret cloud level if you find it
         */
        if (Level.level == 4)
        {
            if (GameObject.Find("Body").transform.position.y > 5)
            {
                SceneManager.LoadScene("SecretCloudLevel", LoadSceneMode.Single);
            }
        }

        MovePlayer();
    }