纳金网
标题:
小地图代码
[打印本页]
作者:
王者再临
时间:
2014-12-31 21:58
标题:
小地图代码
创建一个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();
}
}
复制代码
欢迎光临 纳金网 (http://c-www.narkii.com/club/)
Powered by Discuz! X2.5