예제 #1
0
    //Upon colliding with object called 'collider' reset position
    private void OnTriggerEnter2D(Collider2D other)
    {
        //Find gamemode script
        GameObject gamemode       = GameObject.Find("Gamemode");
        Gamemode   gamemodeScript = gamemode.GetComponent <Gamemode>();

        //The four options for getting the answer correct
        //Going East
        if (other.gameObject.name == "Collider East" && gamemodeScript.wrongAns != 1)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine / functions
            StartCoroutine("SetWin");
            gamemodeScript.BuildEastBlock();
            return;
        }

        //Going North
        if (other.gameObject.name == "Collider North" && gamemodeScript.wrongAns != 2)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine / functions
            StartCoroutine("SetWin");
            gamemodeScript.BuildNorthBlock();
            return;
        }

        //Going West
        if (other.gameObject.name == "Collider West" && gamemodeScript.wrongAns != 3)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine / functions
            StartCoroutine("SetWin");
            gamemodeScript.BuildWestBlock();
            return;
        }

        //Going South
        if (other.gameObject.name == "Collider South" && gamemodeScript.wrongAns != 4)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine / functions
            StartCoroutine("SetWin");
            gamemodeScript.BuildSouthBlock();
            return;
        }

        //The four options for getting the answer Wrong
        //Going East
        if (other.gameObject.name == "Collider East" && gamemodeScript.wrongAns == 1)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine
            SetLose();
            return;
        }

        //Going North
        if (other.gameObject.name == "Collider North" && gamemodeScript.wrongAns == 2)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine
            SetLose();
            return;
        }

        //Going West
        if (other.gameObject.name == "Collider West" && gamemodeScript.wrongAns == 3)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine
            SetLose();
            return;
        }

        //Going South
        if (other.gameObject.name == "Collider South" && gamemodeScript.wrongAns == 4)
        {
            //Reset player's powision to middle of area
            transform.position = new Vector2(-0.5f, 6f);

            //calling coroutine
            SetLose();
            return;
        }
    }