Create A Game Minimap Using C# Scripts In Unity

Introduction

 
This article demonstrates how to make a Game Minimap using C# scripts in unity.
 
Prerequisites
 
Unity environment version 2019.3.0f6.
 

Create the Project

 
Create A Game Minimap Using C# Scripts In Unity
 
First, you have to open the Unity project. Create the plane.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the plane as floor in scene view.
 
Create A Game Minimap Using C# Scripts In Unity
 
Click on the "GameObject" menu in the menu bar. Select 3D objects and pick the "Capsule" option. The capsule will be added to the scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the Capsule as Player in Scene view.
 
Create A Game Minimap Using C# Scripts In Unity
 
Click on the "GameObject" menu in the menu bar. Select 3D objects and pick the "Cylinder" option. The cylinder will be added to the scene View
 
Create A Game Minimap Using C# Scripts In Unity
 
Select the Cylinder on Click (Ctrl + D). Create a duplicate multiple Cylinder.
 
Create A Game Minimap Using C# Scripts In Unity
 

Create a C# Script

 
Right-click on Assets. Select Create >> C# script.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the script as MoveScripts.
 
Create A Game Minimap Using C# Scripts In Unity
 
Double click on the MoveScript script. The MonoDevelop-Unity editor will open up. 
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MoveScript : MonoBehaviour
  5. {
  6. [SerializeField] private float speed;
  7. void Update()
  8. {
  9. Vector3 keyboardInput = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
  10. transform.Translate(keyboardInput * speed * Time.deltaTime);
  11. }
  12. }
Save the Program.
 
Drag and drop the MoveScripts onto the Player.
Create A Game Minimap Using C# Scripts In Unity
 
Set the Player Speed in the Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Add the new camera in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Now click Camera and set the Transform & Projection in Scene View.  
 
 Create A Game Minimap Using C# Scripts In Unity
 
Rename the Camera as MinimapCamera.
 
Create A Game Minimap Using C# Scripts In Unity
 
Click on the "GameObject" menu in the menu bar. Select UI objects and pick the "Canvas" option. The canvas will be added to the scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Set the canvas UI Scale Mode In Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Select Canvas add the Panel in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Set the Panel Rect Transform in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the Panel as Minimap Background.
 
Create A Game Minimap Using C# Scripts In Unity
 
Select MinimapBackground and add the Image in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the Image as MinimapRander.
 
Create A Game Minimap Using C# Scripts In Unity
 

Create a Render Texture

 
Right-click on Assets. Select Create >> Render Texture.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the Render Texture as MinimapCamera.
 
Create A Game Minimap Using C# Scripts In Unity
 
Select MinimapRender Add Component Click on Raw Image in Scene View.
Create A Game Minimap Using C# Scripts In Unity
 
Drag N Drop MinimapCamera to MinimapRender RawImage.
 
Create A Game Minimap Using C# Scripts In Unity
 
Drag N Drop MinimapCamera to MinimapCamera ( Target Texture ).
 
Create A Game Minimap Using C# Scripts In Unity
 

Create a C# Script

 
Right-click on Assets. Select Create >> C# script.
 
Create A Game Minimap Using C# Scripts In Unity
 
Rename the scripts as MinimapCamera.
 
Create A Game Minimap Using C# Scripts In Unity
 
Double click on the MinimapCamera script. The MonoDevelop-Unity editor will open up.
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MinimapCamera : MonoBehaviour
  5. {
  6. [SerializeField] private Transform PlayerTransform;
  7. [SerializeField] private float yoffset;
  8. private void LateUpdate()
  9. {
  10. Vector3 targetPosition = PlayerTransform.position;
  11. targetPosition.y += yoffset;
  12. transform.position = targetPosition;
  13. }
  14. }
Save the Program.
 
Drag and drop the MinimapCamera Scripts onto the MinimapCamera.
 
Create A Game Minimap Using C# Scripts In Unity
 
Drag and drop the Player onto the Minimap Camera Scripts (Player Transform and Set the Offset).
 
 Create A Game Minimap Using C# Scripts In Unity
 
Click on the "Edit" menu in the menu bar. Select Player Setting objects and pick the "Tag and Layers" option. Click on layers create the user Layers (Enemies) to the scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Click on the "Edit" menu in the menu bar. Select Player Setting objects and pick the "Tag and Layers" option. Click on layers create the user Layers (RenderToMinimap) to the scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Select the Cylinder and add the user layers (Enemies).
 
Create A Game Minimap Using C# Scripts In Unity
 
Select the All Cylinder Add to sphere in scene View.
 
Select the Sphere Add the user Layers ( RenderToMinimap ).
 
Create A Game Minimap Using C# Scripts In Unity
 
Select the MinimapCamera and click On Culling Mask.  Set the RenderToMinimap.
 
 Create A Game Minimap Using C# Scripts In Unity
 
Create The Materials
 
Create A Game Minimap Using C# Scripts In Unity
 
Drag n drop materials to Cylinder in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Drag N Drop materials to Sphere in Scene View.
 
Create A Game Minimap Using C# Scripts In Unity
 
Click on the Play button. Start the Game Minimap in Unity.
 
Create A Game Minimap Using C# Scripts In Unity
 

Summary

 
I hope you understood how to perform Game Minimap using C# scripts in unity.


Similar Articles