top of page

Unity - Creating a Minimap

Part of UI in games is a Minimap, which the player can use to navigate the world their character in-game is in. Creating one of these in Unity is relatively easy, and is something I did.



Originally, we were going to follow a tutorial using this project file, but unfortunately there were too many things missing out of the version we had to download, so I instead created a quick environment in Unity to work with instead.



Here's the first environment I made, which didn't have any programming or scripts. I was mainly just using this as practice as opposed to properly implementing it into a game.



I started trying to assemble the camera for the minimap, but due to a number of issues, I had to start over.



Here is my second attempt in Unity, which looks far better than the first. I created a fake player and moved the game camera around to focus on it, and then added a second camera, and made give a birdseye view of the play area.


I did this by reseting the transformation of the camera, moving it up and rotating it to face down. I made sure that the the camera was set to orthographic, as that would give clear boundaries to the player about obstacles if this were a real game.



The next thing I did was create a Raw Image, which is found in the UI section of Create. I went into 2D mode and then positioned and anchored the Raw Image to the top right corner of the screen, which is were I want the minimap to be. I made sure the position was the same for both X and Y so that everthing looked even.



The next thing to do is to add my camera view as the texture for the Raw Image. To do this, I need to create a render texture. I went down into the Project Panel and created a new Render Texture, and set it to the same size as the Raw Image (170 x 170). The only thing left to do is to drag my minimap camera view into the Texture of the Render Texture.



And now I have a minimap in the corner of my screen, which would stay during the whole game. I can also add a border to the map by going through the same process.



Hovever, the camera doesn't currently follow the player. If this is something I wanted in a game, here is the code I would need to attach to the camera. And if I wanted the map to rotate with the player, I would need to add an aditional line to the script.



Sources:


Comments


bottom of page