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;
獲取所以物體的坐標離本物體的距離
}
通過獲取所以物體離本物體的距離判斷最小的距離值