|
using UnityEngine;
using System.Collections;
public class jietu:MonoBehaviour {
public bool flag1 = true ;
public Texture[] MinMap =new Texture[7] ;
public GUISkin background;
//public Texture biankuang ;
public Texture[] MMBtn=new Texture[2];
public Texture playerTexture ;
float cubePosX=0 ;
float cubePosY=0 ;
public GameObject MyPlayer ;
public GameObject MyPlane;
float planeWidth;
private float planeX;
private float planeZ;
public bool flag2=false;
public Texture[] texture=new Texture[2];
void Start()
{
if (MyPlane == null)
return;
planeWidth= MyPlane.GetComponent<MeshFilter>().mesh.bounds.size.x*MyPlane.transform.localScale.x;//因为plane是正方形,所以只取了宽
planeX = MyPlane.transform.position.x;
planeZ = MyPlane.transform.position.z;
// MinMap[0]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/myMap.png", typeof(UnityEngine.Texture));
// MinMap[1]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/biankuang.png", typeof(UnityEngine.Texture));
// MinMap[2]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/hidden.png", typeof(UnityEngine.Texture));
// MinMap[3]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/zhankai.png", typeof(UnityEngine.Texture));
// MinMap[4]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/play.png", typeof(UnityEngine.Texture));
// MinMap[5]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/jingyin.png", typeof(UnityEngine.Texture));
// MinMap[6]=(Texture)Resources.LoadAssetAtPath("Assets/Materials/gulaochengbao/Texture/lan wa.jpg", typeof(UnityEngine.Texture));
}
void OnGUI ()
{
//float btnW = 60.0f;
GUI.skin = background;
//float btnH = 40.0f;
if (MinMap == null)
return;
int i = 0;
MMBtn [0] = MinMap [3];
MMBtn [1] = MinMap [2];
playerTexture = MinMap [6];
if (flag1) {
i++;
GUI.DrawTexture (new Rect (Screen.width - MinMap[0].width, 0, MinMap[0].width, MinMap[0].height), MinMap[0]);
GUI.DrawTexture(new Rect(Screen.width - MinMap[1].width, 0,MinMap[1].width,MinMap[1].height),MinMap[1]);
if(cubePosX>0&&cubePosY<MinMap[0].height){
GUI.DrawTexture (new Rect (cubePosX + Screen.width - MinMap[0].width, cubePosY, 10, 10), playerTexture);
}
}
//绘制小地图现实与隐藏按钮
if(GUI.Button (new Rect(Screen.width - MinMap[1].width-MMBtn[i].width-10,0,25,25),MMBtn[i])){
flag1 = !flag1;
}
int j = 0;
texture [0] = MinMap [4];
texture [1] = MinMap [5];
if (flag2) {
j++;
audio.Pause ();
}
if (GUI.Button(new Rect(Screen.width-282, 25, 25, 25), texture[j])){
audio.Pause();
audio.Play();
flag2=!flag2;
}
}
void Update()
{
if (MinMap == null)
return;
if (MyPlane == null)
return;
cubePosX = MinMap[0].width * (MyPlayer.transform.position.x-planeX + planeWidth/2) / planeWidth; //+ MinMap.width / 2;//根据palyer在plane的比例关系,映射到对应地图位置。
cubePosY = -(MinMap[0].height * (MyPlayer.transform.position.z-planeZ - planeWidth/2) / planeWidth); //+ MinMap.height / 2;
}
}
|
评分
-
查看全部评分
|