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?
Answer by Brocccoli · Mar 19, 2016 at 08:38 PM
I have found the perfect answer on this website.
http://code.tutsplus.com/tutorials/how-to-add-your-own-tools-to-unitys-editor--active-10047
Turns out there's an OnDrawGizmos() method that can be written in MonoBehaviors that does exactly what I want.
Answer by The-Aidency · Mar 19, 2016 at 08:22 PM
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);
thanks. Forgot I could get final coordinates from hit.point