找回密码
 立即注册
楼主: money

[脚本] Unity3D小地图代码

[复制链接]
发表于 2013-1-7 20:17 | 显示全部楼层 |阅读模式
  1. @script ExecuteInEditMode()
  2. public var blip : Texture; //定義一個指針文件代表角色
  3. public var radarBG : Texture; //地圖背景圖片,我直接用場景里我創建的render texture
  4. public var centerObject : Transform; //選擇角色的物體的位置信息
  5. public var mapScale = 0.3; //地圖縮放
  6. public var mapCenter = Vector2(50,50); //地圖中心
  7. function OnGUI () {
  8.    
  9.     bX=centerObject.transform.position.x * mapScale;
  10.     bY=centerObject.transform.position.z * mapScale;
  11.       
  12.     bX=centerObject.transform.position.x * mapScale;
  13.     bY=centerObject.transform.position.z * mapScale;
  14.       
  15.     GUI.DrawTexture(Rect(mapCenter.x-32,mapCenter.y-32,**,**),radarBG);
  16.    // 上面的mapCenter.x-32是地圖的x位置,mapCenter.y-32是y位置,**,**是地圖的大小
  17.     DrawBlipsForEnemies();
  18. }
  19. function DrawBlipsForCows(){
  20.    
  21.     var gos : GameObject[];
  22.     gos = GameObject.FindGameObjectsWithTag("Cow");
  23.     var distance = Mathf.Infinity;
  24.     var position = transform.position;
  25.     for (var go : GameObject in gos)  {
  26.         drawBlip(go,blip);
  27.     }
  28. }
  29. function drawBlip(go,aTexture){
  30.    
  31.     centerPos=centerObject.position;
  32.     extPos=go.transform.position;
  33.    
  34.     dist=Vector3.Distance(centerPos,extPos);
  35.    
  36.     dx=centerPos.x-extPos.x;
  37.     dz=centerPos.z-extPos.z;
  38.    
  39.     deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
  40.    
  41.     bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
  42.     bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
  43.    
  44.     bX=bX*mapScale;
  45.     bY=bY*mapScale;
  46.    
  47.     if(dist<=200){
  48.        GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,2,2),aTexture);
  49.     }
  50. }
  51. function DrawBlipsForEnemies(){
  52.    
  53.     var gos : GameObject&#91;&#93;;
  54.     gos = GameObject.FindGameObjectsWithTag("Enemy");
  55.     var distance = Mathf.Infinity;
  56.     var position = transform.position;
  57.     for (var go : GameObject in gos)  {
  58.     drawBlip(go,blip);
  59.     }
  60. }
复制代码
发表于 2013-2-3 14:13 | 显示全部楼层
var gos : GameObject&#91;&#93;;
者句提示错误怎么办
发表于 2013-2-18 19:51 | 显示全部楼层
谢谢分享{:5_424:}
发表于 2013-3-20 15:25 | 显示全部楼层
谢谢分享{:soso_e100:}
发表于 2013-4-6 21:26 | 显示全部楼层
{:5_430:}{:5_430:}{:5_430:}{:5_430:}
发表于 2013-10-30 10:04 | 显示全部楼层
小白对这里的算法不懂能介绍下吗
发表于 2014-8-11 14:33 | 显示全部楼层

膜拜中。。。。{:soso__7524161091986203637_5:}
发表于 2017-4-10 20:52 | 显示全部楼层
好帖就是要顶
发表于 2017-4-10 21:03 | 显示全部楼层
真心顶
发表于 2017-4-10 21:47 | 显示全部楼层
难得一见的好帖
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-4 00:09 , Processed in 0.856116 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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