**
制作小地图
1.preject面板下右键新建一个rander Texture
2.在人物上方创建图标
3.更改图标图层
4.改变主相机属性面板Culling Mask中可以看到的东西
5.调整摄像机照射范围
6.创建Raw image
7.将前面创建的rander Texture赋值给Raw image
8.创建副相机
9.将rander Texture赋值给副相机
10.更改主人物的图层
11.改变副相机属性面板Culling Mask中可以看到的东西
创建一个脚本
using UnityEngine;
using System.Collections;
public class MiniMapCameraFollow : MonoBehaviour {
private Transform playerTra;
private float xMin;
private float xMax;
private float zMin;
private float zMax;
// Use this for initialization
void Start ()
{
//自动计算边界值
GameObject player = GameObject.FindGameObjectWithTag("Player");
GameObject ground = GameObject.FindGameObjectWithTag("Ground");
playerTra = GameObject.FindGameObjectWithTag("Player").transform;
Vector3 playerSize = player.GetComponent<MeshFilter>().mesh.bounds.size;
Vector3 groundSize = ground.GetComponent<MeshFilter>().mesh.bounds.size;
Vector3 playerScale = player.transform.localScale;
Vector3 groundScale = ground.transform.localScale;
float cameraSize = GameObject.FindGameObjectWithTag("MiniMapCamera").GetComponent<Camera>().orthographicSize;
float x = groundSize.x * groundScale.x / 2 - playerSize.x * playerScale.x / 2 - cameraSize / 2;
float z = groundSize.z * groundScale.z / 2 - playerSize.z * playerScale.z / 2 - cameraSize / 2;
xMin = -x + ground.transform.localPosition.x;
xMax = x + ground.transform.localPosition.x;
zMin = -z + ground.transform.localPosition.z;
zMax = z + ground.transform.localPosition.z;
}
// Update is called once per frame
void Update ()
{
float x = Mathf.Clamp(playerTra.localPosition.x,xMin,xMax);
float z = Mathf.Clamp(playerTra.localPosition.z,zMin,zMax);
transform.position = new Vector3(x,5,z);
}
**