昨天研究了下小地图论坛上的代码看不懂,主要是算法,求大神解释
@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);
}
}
小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )
GMT+8, 2024-5-28 07:15 , Processed in 0.044337 second(s), 15 queries .
Powered by Discuz! X3.5 Licensed
© 2001-2024 Discuz! Team.