先上效果图↓↓↓

1. 先是制作小地图
- 在Project面板中创建一个RenderTexture,将这个RenderTexture放在Camera中的TargetTexture中
- 新建一个RawImage对象,将RenderTexture赋值给它
2. 实现点击小地图位置,真实位置也随之改变
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.AI;
public class Move : MonoBehaviour,IPointerClickHandler
{
public GameObject player;
public GameObject plane;
private float mapWidth;
private float mapHeight;
private float planeWidth;
private float planeHeight;
private Vector2 tempVector;
void Start ()
{
mapWidth = this.GetComponent<RectTransform>().rect.width;
mapHeight = this.GetComponent<RectTransform>().rect.height;
planeWidth = plane.GetComponent<MeshRenderer>().bounds.size.x;
planeHeight = plane.GetComponent<MeshRenderer>().bounds.size.z;
}
void Update ()
{
player.transform.position = Vector3.Lerp(player.transform.position,new Vector3(tempVector.x,0,tempVector.y), Time.deltaTime*0.5f);
}
public void OnPointerClick(PointerEventData eventData)
{
tempVector = new Vector2(eventData.position.x - Screen.width + mapWidth, eventData.position.y - Screen.height + mapHeight);
Debug.Log(tempVector);
tempVector = new Vector2((tempVector.x/mapWidth)*planeWidth - planeWidth/2,(tempVector.y/mapHeight)*planeHeight-planeHeight/2);
Debug.Log(tempVector);
}
}