Making a raycast visible
I have a ray that I would like to make that cast a solid line that the camera can see. Thank you!!
Answer by Tehnique · Apr 03, 2015 at 11:05 AM
Depends what you need it for, if it's only for debug purposes, you can use Debug.DrawLine and draw a line from the raycast start to the hit position.
If you need the line in game, you can use the LineRenderer, jsut read up on it, it's quite easy to implement. Also, check out these awesome examples.
Answer by HasnainKhan · Jan 07, 2017 at 08:08 PM
You can use Debug.DrawRay like this . And let me know if you got any problem with understanding the code I will try my best to help you . :)if(Physics.Raycast(transform.position,transform.forward,out hit)) { if (hit.collider.gameObject.tag == "Tagged") { Debug.DrawRay(transform.position, transform.forward, Color.green); print("Hit"); } }
Answer by JedBeryll · Apr 03, 2015 at 11:06 AM
You could use a line renderer in combination with your raycast. http://docs.unity3d.com/Manual/class-LineRenderer.html