1、射线检测
Vector3 pos = Vector3.one;
Vector3 dir = Vector3.zero;
RaycastHit[] rhs = Physics.RaycastAll(pos, dir);
if (rhs.Length > 0)
{
Debug.Log("碰撞点:" + rhs[0].point);
}
2、直线检测1
Vector3 pos = Vector3.one;
Vector3 dir = Vector3.zero;
float distance = 0;
RaycastHit[] rhs = Physics.RaycastAll(pos, dir, distance);
if (rhs.Length > 0)
{
Debug.Log("碰撞点:" + rhs[0].point);
}
3、直线检测2
Vector3 from = Vector3.one;;
Vector3 to = Vector3.zero;;
RaycastHit rh;
if (Physics.Linecast(from, to, out rh, LayerMask.GetMask("Terrain")))
{
Debug.Log("碰撞点" + rh.point);
}
|