测试代码
public class CollisionTest : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) { if (Physics.SphereCast(Vector3.zero, 0.5f, Vector3.forward, out var hitInfo, 5)) { Debug.Log($"hit: {hitInfo.point.x},{hitInfo.point.y},{hitInfo.point.z}"); } } } void OnDrawGizmos() { Gizmos.color = Color.cyan;//更改颜色 Gizmos.DrawLine(Vector3.zero, Vector3.forward * 5); } }
检测范围
1) 从原点+半径距离开始,半径为0.5的圆柱体射线,
2) 排除掉一开始的0.5半径的球形(灰色那个)
参考
Unity - Raycast 射线检测 (bbsmax.com)
标签:SphereCast,point,Vector3,0.5,hitInfo,理解,Physics From: https://www.cnblogs.com/sailJs/p/17035509.html