[Unity3d]自制圆形小地图
来源:互联网 发布:come alive动作数据 编辑:程序博客网 时间:2024/04/30 19:40
继续今天的学习心得,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的插件,用来制作小地图就更炫更专业了,这里只是一个粗糙的小地图。你也可以尝试用一下更专业的插件来开发。
更专业的插件开发小地图请看:http://blog.csdn.net/dingxiaowei2013/article/details/18669919
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:375151422 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================
转载请注明出处:http://blog.csdn.net/dingxiaowei2013/article/details/18571083
附加:添加遮罩实现圆形小地图
效果:
实现步骤:
1.准备一个场景的缩略小地图,用相机照着,相机呈现出来的相投影到RenderTexture上
2.新建遮罩shader
Shader "Custom/Mask" { Properties { _MainTex ("Main Texture", 2D) = "white" {} _Mask("Mask Texture",2D)="white"{} } SubShader { Tags{"Queue"="Transparent"} Lighting On Zwrite off Blend SrcAlpha OneMinusSrcAlpha pass { SetTexture[_Mask]{combine texture} SetTexture[_MainTex]{combine texture,previous} } }}3.新建一个材质球,并附上上面的shader,选择对应的白色圆形遮罩图和相机呈的相RenderTexture
4.将刚刚创建的材质赋给UITexture【NGUI】即可
4 1
- [Unity3d]自制圆形小地图
- 简单2步学会Unity3D 游戏圆形小地图!
- Cmaera圆形小地图
- Unity3D之自制小钟表
- unity3d小地图代码
- unity3D 小地图
- Unity3D-小地图制作
- unity3d之小地图
- Unity3d+moba+小地图
- 【Unity3D自学记录】Unity3D之自制小钟表
- CEGUI下圆形小地图实现
- unity3d 小地图实现思路
- Unity3D 制作右上角小地图
- [Unity3d]小地图的制作
- Unity3D+moba+小地图视野
- Unity3D 小地图的制作
- Unity3D如何构造小地图
- 自制圆形文字ICON
- Creating a Basic Debugger
- 分布式概论课程知识总结1
- 第18章 applet和多媒体
- 01我为什么学Unity3d
- nginx/FastCGI
- [Unity3d]自制圆形小地图
- iframe 父窗口和子窗口相互的调用方法集锦
- Configuring QoS
- 第19章 二进制IO
- 云梯的多NameNode和跨机房之路
- 深入剖析阿里巴巴云梯YARN集群
- 由U_BOOT_CMD命令想到的
- struts2中 # % $ 的区别和用法
- MySQL索引背后的数据结构及算法原理