using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject a;
public GameObject b; //a,b 分别定义两个公共GameObject对象//
private Vector3 m;
private Vector3 n;
void Update () {
if (a==null || b==null) {
print("a or b = null");
return;
} //如果a或者是b实例化失败就跳出函数 //
//m,n定义两个私有 Vector3类型
m=a.transform.position;
n=b.transform.position;
Debug.Log(Vector3.Distance(m,n));
//函数Vector3.Distance计算a,b间距,并在控制台输出
}
}
Unity3D获得两GameObject间距
最新推荐文章于 2021-06-30 15:00:32 发布