找回密码
 立即注册
查看: 14320|回复: 157

[脚本] Unity3D 简单实用小地图

   火.. [复制链接]
发表于 2012-9-14 10:22 | 显示全部楼层 |阅读模式
小图像下载:
游客,如果您要查看本帖隐藏内容请回复

效果图:
  1. @script ExecuteInEditMode()
  2. public var Enemy_ : Texture; //define enemy texture
  3. public var Box_:Texture;//define the box texture
  4. public var Player_:Texture;//define player texture
  5. public var radarBG : Texture; //small map texture
  6. public var centerObject : Transform; //chracter position
  7. public var mapScale = 0.3; //地圖縮放
  8. public var mapCenter = Vector2(50,50); //地圖中心
  9. function OnGUI () {
  10.    
  11.     bX=centerObject.transform.position.x * mapScale;
  12.     bY=centerObject.transform.position.z * mapScale;
  13.       
  14.     bX=centerObject.transform.position.x * mapScale;
  15.     bY=centerObject.transform.position.z * mapScale;
  16.       
  17.     GUI.DrawTexture(Rect(mapCenter.x-55,mapCenter.y-50,128,128),radarBG);
  18.    // 上面的mapCenter.x-32是地圖的x位置,mapCenter.y-32是y位置,64,64是地圖的大小
  19.     DrawBlipsForEnemies();
  20.         DrawBlipsForPlayer();
  21.         DrawBlipsForBox();
  22. }
  23. function DrawBlipsForBox(){ //draw box texture in small map
  24.    
  25.     var gos : GameObject[];
  26.     gos = GameObject.FindGameObjectsWithTag("Box");
  27.     var distance = Mathf.Infinity;
  28.     var position = transform.position;
  29.     for (var go : GameObject in gos)  {
  30.         drawBlip(go,Box_);
  31.     }
  32. }
  33. function DrawBlipsForPlayer(){ //draw player texture in small map
  34.    
  35.     var gos : GameObject[];
  36.     gos = GameObject.FindGameObjectsWithTag("Player");
  37.     var distance = Mathf.Infinity;
  38.     var position = transform.position;
  39.     for (var go : GameObject in gos)  {
  40.         drawBlip(go,Player_);
  41.     }
  42. }
  43. function DrawBlipsForEnemies(){ //draw enemy texture in small map
  44.    
  45.     var gos : GameObject[];
  46.     gos = GameObject.FindGameObjectsWithTag("Enemy");
  47.     var distance = Mathf.Infinity;
  48.     var position = transform.position;
  49.     for (var go : GameObject in gos)  {
  50.     drawBlip(go,Enemy_);
  51.     }
  52. }
  53. function drawBlip(go,aTexture){ //draw position in small map
  54.    
  55.     centerPos=centerObject.position;
  56.     extPos=go.transform.position;
  57.    
  58.     dist=Vector3.Distance(centerPos,extPos);
  59.    
  60.     dx=centerPos.x-extPos.x;
  61.     dz=centerPos.z-extPos.z;
  62.    
  63.     deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
  64.    
  65.     bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
  66.     bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
  67.    
  68.     bX=bX*mapScale;
  69.     bY=bY*mapScale;
  70.    
  71.     if(dist<=200){
  72.        GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,16,16),aTexture);
  73.     }
  74. }
复制代码
注意: box 为宝箱   enemy为敌人  palyer为玩家

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 3鲜花 +3 +2 收起 理由
lukylukymg + 1 + 1 赞一个!
number13 + 1
djboyle + 1 + 1

查看全部评分

发表于 2012-11-7 19:34 | 显示全部楼层
谢谢分享,看看在
发表于 2012-11-9 15:09 | 显示全部楼层
无回帖,不论坛,这才是人道。
发表于 2012-11-12 15:41 | 显示全部楼层
现在需要,谢谢分享,研究!
发表于 2012-11-15 09:58 | 显示全部楼层
研究研究啊
发表于 2012-11-15 11:34 | 显示全部楼层
the variable centerObject of 'ditu' has not been assigned
发表于 2012-11-15 13:23 | 显示全部楼层
学习 !{:5_401:}
发表于 2012-11-16 19:50 | 显示全部楼层

无回帖,不论坛,这才是人道。
发表于 2012-11-19 13:05 | 显示全部楼层
的反对党的顶顶顶顶顶顶顶顶顶顶
发表于 2012-11-21 13:46 | 显示全部楼层
谢谢 分享{:5_404:}{:5_378:}
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-1 22:56 , Processed in 0.103134 second(s), 32 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表