欢迎来到天天文库
浏览记录
ID:57895916
大小:18.98 KB
页数:5页
时间:2020-09-02
《Unity3D小地图功能代码.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Unity3D小地图功能代码Postedon2013年04月07日byU3d/Unity3D脚本/插件/被围观318次Unity3D小地图功能代码:usingUnityEngine;usingSystem.Collections;publicclassminMap:MonoBehaviour{publicTexturebackGround;//小地图背景publicTextureplayerMiniLogo;//玩家标记(可旋转)publicTextureNpcMiniLogo;//NPC标记如建筑publicTextureDirectionArrow;p
2、ublicTransformPlayer;//玩家所在位置publicfloatarrowAngle=0;//realmapsize(3dworldunits)publicfloatmapWidth=2000;//场景实际宽publicfloatmapHeight=2000;//场景实际高//minimapsize(texture)publicfloatminiMapWidth=256;//小地图宽publicfloatminiMapHeight=256;//小地图高//privatefloatbackAlpha=0.9f;//背景透明度publicstr
3、ingNpcTags="NPC";privateGameObject[]DrawNpcs;//UsethisforinitializationvoidStart(){DrawNpcs=GameObject.FindGameObjectsWithTag(NpcTags);}//UpdateiscalledonceperframevoidUpdate(){}voidOnGUI(){DrawMiniMap(Screen.width-miniMapWidth,Screen.height-miniMapHeight,2);}voidDrawMiniMap(float
4、LeftX,floatLeftY,intPointSize){GUI.depth=-10;GUI.color=newColor(1,1,1,backAlpha);GUI.DrawTexture(newRect(LeftX,LeftY,miniMapWidth,miniMapHeight),backGround);//drawnpcsif(DrawNpcs!=null){for(inti=0;i5、wTexture(newRect(LeftX+(npc.transform.position.x/mapWidth)*miniMapWidth-(PointSize/2),LeftY+(miniMapHeight-(npc.transform.position.z/mapHeight)*miniMapHeight-(PointSize/2)),PointSize,PointSize),NpcMiniLogo);}}//drawdirectionarrow绘制玩家图标可旋转箭头if(DirectionArrow!=null){GUI.depth=20;GUI6、.color=newColor(1,1,1,1);GUIUtility.RotateAroundPivot(Player.eulerAngles.y,newVector2(LeftX+(Player.position.x/mapWidth)*miniMapWidth,LeftY+(miniMapHeight-(Player.position.z/mapHeight)*miniMapHeight)));GUI.DrawTexture(newRect(LeftX+(Player.position.x/mapWidth)*miniMapWidth-(Direct7、ionArrow.width/2),LeftY+(miniMapHeight-(Player.position.z/mapHeight)*miniMapHeight-(DirectionArrow.height/2)),DirectionArrow.width,DirectionArrow.height),DirectionArrow);GUI.matrix=Matrix4x4.identity;}}}
5、wTexture(newRect(LeftX+(npc.transform.position.x/mapWidth)*miniMapWidth-(PointSize/2),LeftY+(miniMapHeight-(npc.transform.position.z/mapHeight)*miniMapHeight-(PointSize/2)),PointSize,PointSize),NpcMiniLogo);}}//drawdirectionarrow绘制玩家图标可旋转箭头if(DirectionArrow!=null){GUI.depth=20;GUI
6、.color=newColor(1,1,1,1);GUIUtility.RotateAroundPivot(Player.eulerAngles.y,newVector2(LeftX+(Player.position.x/mapWidth)*miniMapWidth,LeftY+(miniMapHeight-(Player.position.z/mapHeight)*miniMapHeight)));GUI.DrawTexture(newRect(LeftX+(Player.position.x/mapWidth)*miniMapWidth-(Direct
7、ionArrow.width/2),LeftY+(miniMapHeight-(Player.position.z/mapHeight)*miniMapHeight-(DirectionArrow.height/2)),DirectionArrow.width,DirectionArrow.height),DirectionArrow);GUI.matrix=Matrix4x4.identity;}}}
此文档下载收益归作者所有