- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
制作小地图的代码- 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();
-
- }
-
- }
复制代码 |
|