- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
创建一个c#脚本,挂在摄像机上,然后将变量拖入对应位置即可,可以实现小地图的拖动功能- using UnityEngine;
-
- using System.Collections;
-
- public class mymap : MonoBehaviour {
-
- // Use this for initialization
-
- public Texture map ;
-
- public Texture playerTexture ;
-
- float cubePosX=0 ;
-
- float cubePosY=0 ;
-
- public GameObject player ;
-
- public GameObject plane;
-
- float planeWidth;
-
- public Rect windowRect = new Rect(0,0,100,100);
-
- void Start()
-
- {
-
- planeWidth=plane.GetComponent<MeshFilter>().mesh.bounds.size.x*plane.transform.localScale.x;
-
- }
-
- void OnGUI ()
-
- {
-
- windowRect = GUI.Window(0,windowRect,draw,“”);
-
- }
-
- void Update()
-
- {
-
- cubePosX =map.width*player.transform.position.x/planeWidth+map.width/2;//根据palyer在plane的比例关系,映射到对应地图位置。
-
- cubePosY =map.height*player.transform.position.z/planeWidth+map.height/2;
-
- if(Input.GetMouseButton(0))
-
- {
-
- }
-
- }
-
- void draw(int windowID)
-
- {
-
- GUI.DrawTexture(new Rect(0,0,map.width/2,map.height/2),map);
-
- GUI.DrawTexture(new Rect(cubePosX,cubePosY,15,15),playerTexture);
-
- GUI.DragWindow();
-
- }
-
- }
复制代码 |
|