小地图

  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,64,64),radarBG);   
  16.    // 上面的mapCenter.x-32是地圖的x位置,mapCenter.y-32是y位置,64,64是地圖的大小   
  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[];   
  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. }  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值