MINING QUEST: ‘Run Away’ - Solutions

Quest: Mining Quest
Challenge: Run Away

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

At first, I was worried, that I need to remove rocks (if there are any) in the desired spot. But the exit works as intended layered on top, so no problem there.

I already put in variables for the size, so I used those and multiplied with 0 or 1 randomly for x and y.

    private void SpawnExit()
    {
        int xExit = Random.Range(0, 2) * (xSize - 1);
        int yExit = Random.Range(0, 2) * (ySize - 1);

        GameObject newExit = Instantiate(exitPrefab, new Vector2(xExit, yExit), Quaternion.identity);
    }
2 Likes

Nice way of finding random corners

1 Like

Oh I like how clean this is. I ended up making an array with four Vector3 for the different corners but of course that used a lot of ‘magic numbers’ that we’re supposed to avoid.

1 Like