美文网首页
Unity创建小地图

Unity创建小地图

作者: 玄策丶 | 来源:发表于2018-07-28 15:24 被阅读0次

    一、

    创建小地图.png

    二、

    新建相机,调节相机俯视场景,挂载脚本(可点击移动)

    using UnityEngine;
    using System.Collections;
    public class mapCam : MonoBehaviour {
        public static mapCam Instance;
        Camera _mapCam;//小地图相机
        GameObject player;//需要移动的物体
        /// <summary>
        /// 小地图的开关
        /// </summary>
        public  bool canSmallMap;
        private bool ifDiMian = true;
        void Awake () {
            Instance = this;
            canSmallMap = true;
            _mapCam=GetComponent<Camera>();//获取相机
            player = GameObject.FindGameObjectWithTag("Player");//获取物体
            //配置点击区域
            //transform.GetChild(0).gameObject.tag = "floor";
            //transform.GetChild(0).GetComponent<MeshRenderer>().enabled = false;
            //transform.GetChild(0).GetComponent<MeshRenderer>().receiveShadows = false;
           // transform.GetChild(0).GetComponent<MeshRenderer>().castShadows = false;
        }
        void Update () 
        {
            if (Input.GetMouseButton(0))
            {
                if (canSmallMap)
                {
                    Ray ray = _mapCam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        StartCoroutine("Wait1S", 0.7f);
                        canSmallMap = false;                                  
                        if (ifDiMian)
                        {
                            if (hit.collider.tag == "floor")
                            {
                                //上 -- 上
                                Vector3 goTo = new Vector3(hit.point.x, 0.8f, hit.point.z);
                                //移动到模型
                                iTween.MoveTo(player, iTween.Hash("position", goTo, "time", 0.01f, "looktarget", goTo, "delay", 0.1f));
                                Debug.Log(1);
                                ifDiMian = true;
                            }
                        }
                        //else
                        //{
                        //    if (hit.collider.tag == "floor")
                        //    {
                        //        //上 --- 下
                        //        //目标位置
                        //        Vector3 goTo = new Vector3(hit.point.x, 0.8f, hit.point.z);
                        //        //移动到模型
                        //        //iTween.MoveTo(player, iTween.Hash("position", goTo, "time", 0.6f, "looktarget", goTo, "delay", 0.1f));
                        //        player.transform.localPosition = goTo;
                        //        Debug.Log(5);
                        //        ifDiMian = true;
                        //    }
                        //}
                        iTween.RotateTo(player, iTween.Hash("x", 0, "y", player.transform.localEulerAngles.y, "z", 0, "time", 0.001f, "delay", 0));
                        Debug.Log(ifDiMian);
                    }
                }
            }
        }
        IEnumerator Wait1S(float waitTime)
        {
            yield return new WaitForSeconds(waitTime);
            canSmallMap = true;
        }
    }
    

    相关文章

      网友评论

          本文标题:Unity创建小地图

          本文链接:https://www.haomeiwen.com/subject/vvpomftx.html