最好用Unity 3D制作小地图,显示、隐藏小地图和背景音乐播放与暂停 [复制链接]

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;
        }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值