获取离自己最近的游戏对象的坐标
{:soso__9662691632502530860_2:}//获取离自己最近的游戏对象的坐标.
function Update()
{
if(networkView.isMine)
{
print(FindClosestEnemy().transform.position);
}
}
// Find the name of the closest enemy
//查找最靠近敌人的信息
function FindClosestEnemy () : GameObject {
// Find all game objects with tag Enemy
//查找标签为test的全部游戏物体
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("test");
var closest : GameObject=GameObject.FindWithTag("test");
//var vect:Vector3 =new Vector3(1.0f,1.0f,1.0f);
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and find the closest one
//遍历他们找到最接近的一个
for (var go : GameObject in gos) {
if(go.transform.position==position)
{
continue;
}
var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
distance = curDistance;
}
}
return closest;
}
感谢楼主的无私分享!{:soso__11402694654016840197_7:}
不错 不错 不错 很不错 楼主是超人 好帖就是要顶 真心顶 很好哦 顶顶多好 难得一见的好帖
页:
[1]