How to Draw a Raycast in Scene view

I have an object in my game that emits a RayCast2D given certain conditions.

What I want to be able to do is preview the RayCast2D in the editor Scene tab before starting the game, so I can do all my editing of the raycast visually by modifying the public properties of the object.

Is this possible in Unity?

Yes, but only during runtime. Use the following command:

var hit : RaycastHit;
var ray = transform.TransformDirection(Vector3.forward);
Physics.Raycast (transform.position, ray, hit, 100);
Debug.DrawLine (transform.position, hit.point,Color.red);

I have found the perfect answer on this website.

Turns out there’s an OnDrawGizmos() method that can be written in MonoBehaviors that does exactly what I want.