小地图的制作
来源:互联网 发布:大连人才网络服务中心 编辑:程序博客网 时间:2024/04/28 10:25
继续今天的学习心得,unity中小地图的制作,实现了小地图中红色小箭头代表场景中的主角,然后人物方向的转变,小地图中箭头也随之改变方向。
效果图
右上角就是小地图,上面有个红色小箭头就是代表主角人物所在场景中的位置,箭头的方向就代表人物所面向的方向。
实现步骤
1.俯视图的制作
首先,我们将Scene场景调成俯视的角度
然后在创建一个Plane,然后点击该对象,在Inspector属性窗口将MeshRenderer取消,
然后记录网格所在的位置,并且取消MeshCollider,用截图工具截取这网格所在的位置,截出一张一模一样大小的图片,这就是我们小地图的来源。截取好了之后记得将MeshCollider勾选上,后面会在代码中需要计算人物所在的位置,也就正是通过这网格文件来计算的。
2.代码的编写
using UnityEngine;using System.Collections;public class map : MonoBehaviour { public Texture map1;//小地形图 public Texture jueseTexture;//标识角色的图片 float juesePosX = 0; float juesePosY = 0; public GameObject player;//角色 public GameObject plane;//地形 float planeWidth;//地形的宽 float planeHeight;//地形的高 float angle = 0; //人物旋转的角度 void Start() { //获取地形的宽高 planeWidth = plane.GetComponent<MeshFilter>().mesh.bounds.size.x * plane.transform.localScale.x; planeHeight = plane.GetComponent<MeshFilter>().mesh.bounds.size.z * plane.transform.localScale.z; print("width+heith:"+planeWidth + ", " + planeHeight); print("bounds:" + plane.GetComponent<MeshFilter>().mesh.bounds); } void OnGUI() { GUI.DrawTexture(new Rect(Screen.width-map1.width, 0, map1.width, map1.height), map1); GUIUtility.RotateAroundPivot(angle, new Vector2((Screen.width - map1.width)+juesePosX + 5, juesePosY + 5)); GUI.DrawTexture(new Rect((Screen.width - map1.width)+juesePosX, juesePosY, 10, 10), jueseTexture); } void Update() { print("people:" + player.transform.position.x + "," + player.transform.position.y); print(1); //根据palyer在plane的比例关系,映射到对应地图位置。 juesePosX = map1.width * player.transform.position.x / planeWidth + map1.width / 2; juesePosY = map1.height * (-player.transform.position.z) / planeHeight + map1.height / 2; print("x:" + juesePosX + "y:" + juesePosY); angle = player.transform.eulerAngles.y-90; print("angle:" + angle); } }将该脚本拖放到Plane上,参数说明:JueseTexture是指小地图中箭头的图片,Player是人物模型的Controller,Plane是指当前带网格的Plane,Map1是指小地图的图片。
当然还有一种KGFMapSystem的插件,用来制作小地图就更炫更专业了,这里只是一个粗糙的小地图。你也可以尝试用一下更专业的插件来开发。
0 0
- 小地图的制作
- 小地图的制作
- [Unity3d]小地图的制作
- Unity3D 小地图的制作
- Uniy的小地图制作
- 右上角的小地图的制作
- NGUI结合Shader制作的小地图
- unity RPG小地图的制作
- [UnityUI]简易的小地图制作
- Unity3D-小地图制作
- Unity小地图制作
- Unity小地图制作
- Unity小地图制作
- 小地图制作
- WOW制作小地图
- 雷达小地图制作
- Unity 制作小地图
- UE4小地图制作 (使用蓝图制作小地图)
- 【强烈推荐】《剑指Offer:名企面试官精讲典型编程题》一书中IT名企经典面试题
- 北大-买房子
- 服务器bash漏洞修补日记——2014/09/30
- OC基础-protocol协议
- Windows Message 消息队列,消息循环,Post消息,Send消息
- 小地图的制作
- 安卓第十夜 亚当的诞生
- Cookie解释以及原理分析
- win7-64位下mysql免安装版配置
- Android开源项目
- 北大-谁是你潜在的朋友
- apache config 1 Bandwidth Mod (apache speed control)
- “波斯公主选驸马”问题的理论分析和数学推导
- Oracle EBS环境下查找数据源(Form篇)