Vector3 a = Camera.main.transform.position;
Vector3 b = transform.position;
float a_b = Vector3.Distance(a, b);
Ray ray = new Ray(a, b - a);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, a_b))
{
}
代码比较简单,可以用来检测两点之间是否存在物体