Transform.InverseTransformPoint 相反变换位置
变换位置从世界坐标到自身坐标。
public Transform A; // 参照物体
public Transform B; // 被转换的物体
void Start()
{
Vector3 realPoint = A.InverseTransformPoint(B.position);
if(realPoint.z > 0)
{
Debug.Log("The A is in front of B");
}
else
{
Debug.Log("The A is behind the B");
}
// 运算方法类似
// Vector3 realPoint = B.position - A.position;
// if(realPoint.z)
// {
Debug.Log("The A is in front of B");
// }
// else
// {
Debug.Log(The A is behind the B);
// }
}
变换位置从世界坐标到自身坐标。
public Transform A; // 参照物体
public Transform B; // 被转换的物体
void Start()
{
Vector3 realPoint = A.InverseTransformPoint(B.position);
if(realPoint.z > 0)
{
Debug.Log("The A is in front of B");
}
else
{
Debug.Log("The A is behind the B");
}
// 运算方法类似
// Vector3 realPoint = B.position - A.position;
// if(realPoint.z)
// {
Debug.Log("The A is in front of B");
// }
// else
// {
Debug.Log(The A is behind the B);
// }
}