Unity 獲取離某個物體最近


public Transform pos;
public Transform pos1;
public float value = 0;
public float value1 = 0;

//坐標和值
// Update is called once per frame
void Update()
{

//判斷離本物體最小的值  就是最近
if (value<value1)
{
print(pos.name);
}
else
{
print(pos1.name);
}
value = (transform.position - pos.position).sqrMagnitude;
value1 = (transform.position - pos1.position).sqrMagnitude;

獲取所以物體的坐標離本物體的距離
}

 

 

 

 通過獲取所以物體離本物體的距離判斷最小的距離值


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM