[Unity]Make raycast visible


It’s been a while.
I’ve been busy with various things, but today I’d like to write an article as a technical note.

I’ve been sending rays from the main camera, rays from specific objects, etc. Recently, I’ve been sending raycasts around a lot, and the following is the basic code (?). The following is the basic code (?).

Distance is the distance, but here I set it to 50.
You can check where the rays are flying to during debugging with Debug.DrawRay.

You can see a red line coming out of the cube, which is the line that Debug.

If the ray hits an object, information about the object can be obtained.
In this sample, the information of the cube on the opposite side is acquired and its name is displayed.