[Unity菜鸟] 射线

时间:2022-12-15 14:20:44

1. 射线用 Physics.Raycast 都可以判断,用 collider.Raycast 只在某些(不明)情况下可以

 void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// if (collider.Raycast(ray, out hit, 100f))
if (Physics.Raycast(ray,out hit ,100f))
{
Debug.DrawLine(ray.origin, hit.point);
Debug.Log(hit.collider.gameObject.name+" "+Time.fixedTime);
}
}