The following is the code I am trying to use, the first thing is that neither DrawLine nor DrawRay will show me a line in the scene view or game view, do I need to add something more? Just for debugging; the second, the distance used to detect the ground must be at least 0.4f in my case, if it is less than 0.4, there will be no collisions with the ground layer. I’ve seen other people using 0.2, or less. Why is that?
You need to enable gizmos in the game view to see the debug lines/rays.
(Toggle the Gizmos button on the top-right of the game view window).
Just depends entirely on where the origin of the ray is and how far it needs to travel before hitting the ground.
So in your case, the origin of your ray is probably just slightly higher up than what you’ve seen in other examples.
Thank you very much! It is true, the origin of the sprite in Unity is its center. And now I can see the cast ray.