Unity联盟 发表于 2012-9-14 10:22

Unity3D 简单实用小地图

小图像下载:
**** Hidden Message *****
效果图:
@script ExecuteInEditMode()
public var Enemy_ : Texture; //define enemy texture
public var Box_:Texture;//define the box texture
public var Player_:Texture;//define player texture
public var radarBG : Texture; //small map texture
public var centerObject : Transform; //chracter position
public var mapScale = 0.3; //地圖縮放
public var mapCenter = Vector2(50,50); //地圖中心
function OnGUI () {
   
    bX=centerObject.transform.position.x * mapScale;
    bY=centerObject.transform.position.z * mapScale;
      
    bX=centerObject.transform.position.x * mapScale;
    bY=centerObject.transform.position.z * mapScale;
      
    GUI.DrawTexture(Rect(mapCenter.x-55,mapCenter.y-50,128,128),radarBG);
   // 上面的mapCenter.x-32是地圖的x位置,mapCenter.y-32是y位置,64,64是地圖的大小
    DrawBlipsForEnemies();
      DrawBlipsForPlayer();
      DrawBlipsForBox();
}
function DrawBlipsForBox(){ //draw box texture in small map
   
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("Box");
    var distance = Mathf.Infinity;
    var position = transform.position;
    for (var go : GameObject in gos){
      drawBlip(go,Box_);
    }
}
function DrawBlipsForPlayer(){ //draw player texture in small map
   
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("Player");
    var distance = Mathf.Infinity;
    var position = transform.position;
    for (var go : GameObject in gos){
      drawBlip(go,Player_);
    }
}
function DrawBlipsForEnemies(){ //draw enemy texture in small map
   
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("Enemy");
    var distance = Mathf.Infinity;
    var position = transform.position;
    for (var go : GameObject in gos){
    drawBlip(go,Enemy_);
    }
}
function drawBlip(go,aTexture){ //draw position in small map
   
    centerPos=centerObject.position;
    extPos=go.transform.position;
   
    dist=Vector3.Distance(centerPos,extPos);
   
    dx=centerPos.x-extPos.x;
    dz=centerPos.z-extPos.z;
   
    deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
   
    bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
    bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
   
    bX=bX*mapScale;
    bY=bY*mapScale;
   
    if(dist<=200){
       GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,16,16),aTexture);
    }
}注意: box 为宝箱   enemy为敌人palyer为玩家

kill 发表于 2012-11-7 19:34

谢谢分享,看看在

dilly123 发表于 2012-11-9 15:09

无回帖,不论坛,这才是人道。

DragonSoul 发表于 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


无回帖,不论坛,这才是人道。

xiaoanhuafei 发表于 2012-11-19 13:05

的反对党的顶顶顶顶顶顶顶顶顶顶

阿豆 发表于 2012-11-21 13:46

谢谢 分享{:5_404:}{:5_378:}
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: Unity3D 简单实用小地图