Generate a small map of Unity games and a map of Unity games

Source: Internet
Author: User

Generate a small map of Unity games and a map of Unity games

Sun Guangdong 2015.6.25

Step-by-step implementation of this function:

Step 1:

In the menu bar, choose GameObject> Create Other> Camera to Create a new Camera, which will be used as a dedicated Camera for the map and adjust its position, set it to Orthographic vertically down above the scene, cancel the perspective, adjust the Size value, change the view Size, and set Viewport Rect to change the position and Size of the camera display area ,:



Step 2:

When a game is running, a small map is displayed in the upper right corner of the screen, but you cannot see the content clearly. The location may be incorrect.

The current small map camera and normal camera display is the same, but it is from top to bottom. Next, we need to make the small map camera focus only on what we need, and use scripts to make the view of the small map camera always a square at whatever resolution.


Step 3:

Create a sphere named dummy and set its material to Red Self-Illumin/Diffuse. It will only be displayed in a small map as the "replacement body" of the enemy, it cannot be displayed in the main camera view. Remove Sphere Collider. We only need its display function.


Step 4:

Create a Layer named dummy and set the Layer dummy of the sphere.


Step 5:

Place the sphere below the level of the enemy's Prefab so that it will move as the enemy moves ,:


Step 6:

Select the main camera and cancel the dummy layer. The sphere will not be displayed in the main camera view ,:



Step 7:

Select the small map camera so that it only displays the level and dummy layers, so that only scenes and sphere can be seen in the small map.



Step 8:

In the same way, you can also create an "substitution body" for the main character, which can be set to a different color than the enemy.


Step 9:

Create the script MiniCamera. cs and assign it to the map camera. Add the following code:

Using UnityEngine; using System. collections; [AddComponentMenu ("Game/MiniCamera")] public class MiniCamera: MonoBehaviour {// Use this for initializationvoid Start () {// float ratio = (float) screen. width/(float) Screen. height; // make the camera view always a positive direction. The first two parameters of rect indicate the XY position, and the last two parameters are the XY size. this. getComponent <Camera> (). rect = new Rect (1-0.2f), (1-0.2f * ratio), 0.2f, 0.2f * ratio );}}

The code here is very short, mainly to make the view of the small map camera always a square.


Step 10:

Because the master camera already has an AudioListener, only one of the components is allowed in the same scenario. Therefore, you must deselect (or delete) the [AudioListener] of the map camera ],.

OK.


If you want to continue to improve the display of a small map, you can also create a model for the scenario.




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.