Saturday, August 13, 2022
HomeGame DevelopmentFull Unity 2D Recreation Tutorial 2019 – Making Mini Map Masks

Full Unity 2D Recreation Tutorial 2019 – Making Mini Map Masks

Sharing is caring!

Full Unity 2D Recreation Tutorial 2019 – Making Mini Map Masks

On this part we will likely be making the mini map after which utilizing a masks to form our mini map into one thing extra interesting then a giant rectangular on the display screen.

Full Unity 2D Recreation Tutorial 2019 – Making Minor Modifications

Earlier than we begin with the mini map we’re going to extend the dimensions of our ships as they’re fairly small and will be tough to see on smaller screens. We would like this to be playable on many alternative display screen sizes so we’ll make it a bit simpler by doubling the ship sizes. To do this we’ll edit the spaceship sprite by clicking on it within the challenge window. Then set the pixels per unit to 64 and click on apply to replace the sprites.

mini map spaceship

As quickly as you have got executed that you will note the spaceships are double their unique measurement. That is solely the pictures although, the colliders are nonetheless the traditional measurement of 0.1. So we have to edit these as nicely.  Choose the participant object and edit the collider so it’s now 0.2 radius. Which is double the earlier worth of 0.1. Our participant is now executed so lets replace the enemies as nicely. This time we’ll edit the enemy prefab. That’s it for the minor modifications.

Full Unity 2D Recreation Tutorial 2019 – Mini Map Digital camera

To ensure that us to make a mini map we want a digicam which will likely be used to create the picture used within the minimap. Consider it like a digicam excessive within the sky over our world. Including a digicam is identical as including some other sport object. Proper click on within the hierarchy view and choose digicam and voila! we now have a digicam. The digicam will want some adjustment to work as a minimap digicam however the very first thing we’ll do is rename it to MapCam. Then we’ll set its projection methodology to Orthographic, its measurement to 7 and its default shade to black. Lastly we replace the culling masks and take away the default layer by clicking on it. This may imply our digicam will ignore something on the default layer and in our case simply draw the participant and enemies.

mini map camera black

Full Unity 2D Recreation Tutorial 2019 – Mini Map Render Texture

Our Digital camera remains to be working like a standard digicam, we wish it to render its view to a picture as a substitute of to us the participant. With a purpose to try this we first have to make a render texture. A render texture is a picture which will likely be created solely at run-time and never saved as a file and will be created by proper clicking the challenge window and clicking create > render texture.

mini map create render texture

Title our render texture to mpRenderTexture and drag it into our digicam’s goal texture. Now our render texture will all the time comprise the view from our digicam and we will use this texture to show on display screen with some UI components.

Full Unity 2D Recreation Tutorial 2019 – Mini Map UI

To show our new mini map render texture we will likely be utilizing the canvas UI. Create an empty object known as MapContainer. This would be the container that holds our map and masks. Inside that create one other empty known as MapMask. This would be the masks which exhibits or hides a part of our map primarily based on the alpha worth of the masks texture we’ll add. Create our third and closing empty contained in the MapMask and name that MapTexture. This may show our render texture.

mini map empty objects

Replace the anchors, pos X, pos Y, width and peak of our 3 new empty objects to match the pictures beneath.

mini map container mini map mask mini map texture

Now that out UI components are positioned properly we’ll add textures and masks to make them present the mini map. Add a Uncooked Picture element to our MapTexture and set the Texture to our mpRenderTexture. It is best to now be capable of see the mini map picture captured by our digicam within the scene and sport view. Nevertheless it’s a giant ugly plain rectangle.

mini map texture raw image

Full Unity 2D Recreation Tutorial 2019 – Mini Map Masks and Masking

Masking permits us to indicate solely a portion of a texture primarily based on the alpha worth of one other texture. For instance we now have our mini map that could be a huge rectangle. We may use a masks to render that rectangle as a circle through the use of a picture of a circle surrounded by clear pixels and making use of it as a masks to our mini map texture.

mini map mask example

mini map mask
Mini Map Masks
mini map mask border
Mini Map Masks Border

Sadly the picture we will likely be utilizing are plain white and won’t present up very nicely on this web site, nonetheless they’ve been captioned so it’s best to be capable of see the place they’re. Obtain these photographs(or get them straight from the github repository) as we will likely be utilizing them for our masking. Now we all know what masking is lets add it to our challenge. On our MapMask object add 2 new elements. An Picture element that can maintain our masks picture and a Masks (script) which can flip our picture right into a masks. Add the Mini Map Masks picture we downloaded to our challenge by dragging it into our photographs folder. Now add it as our supply picture and set the color to black.

mini map mask mask object

It is best to new have a masked mini map and it ought to look one thing just like the picture beneath:

mini map with mask

That is higher however it may use a border to make it stand out a bit extra. On our map container add a brand new Picture element and set the the supply picture to the Mini Map Masks Border picture we downloaded earlier. Alter the colour to one thing you want. I used pure blue at 80 alpha and it’s best to have a pleasant new mini map in your sport.

mini map finished

The ultimate step is to make the digicam comply with the participant. That is made easy by the very fact we already comply with the participant on the principle digicam so all we have to do is so as to add the FollowPlayer script to the MapCam and drag the participant object to the participant object slot in our FollowPlayer script.

It is best to now have one thing much like the picture above (I scaled the map up 2x to be clearer within the picture above)

The completed supply is offered on github right here.



Sharing is caring!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments