Build a UI Mini-map in Unity
Objective: Create a Mini-map.
Using the Mask component and some coding we can get a mini-map working. To start we will need to create a new image and add a Mask component on it. We will disable Show Mask Graphic.
We will make sure the mask is position in the top right corner and it’s anchors.
Next is to create an image as a child to the mask with the sprite you want.
Next we will create an Enemy image, I used just the default sprite when creating an image and changed the color to red. And this will be a child to the map image.
We will do one for the Player as well but just under the canvas.
Now to connect the player and enemy to their mini-map self. Create a script and add four SerializeFields, two Gameobjects and two Images.
Next we will set the Maps local position to a new vector3 and pass in the Players x and z axis to the maps x and y position. We will need to multiply the players x and z axis by -1 to have it move in the right direction.
Next is to do the same thing but for the enemy.
Back in Unity, we will create an Empty object and add this script to it. We will pass in the correct object and images.
With that we have a working mini-map.
Thank you for reading and have a wonderful day!