- Home /
Drawing "Ray like" objects in game
Hello again, I'm working on red dot stuff.
I've wrote a code for detecting hitdist and etc. but i don't want to see line. I only want to see where it ends as red dot. how can i do that ?
At debug time, you can do:
Only draw the end of the ray (very short line, not a dot)
OnGizmosDraw() and Gizmos.DrawSphere() or Gizmos.DrawWireSphere
At runtime or debug:
A mesh you create like a sphere located at the hit point
GameObject.CreatePrimitive(PrimitiveType.Sphere)
Circular texture on a Quad or Sprite positioned at the hit
Circular texture draw on the Viewport space using a GUITexture
Circular texture draw using GUI.DrawTexture()
And some other choices. There are specifics to make any of these work, but I hesitate to add more information without knowing your goals.
Answer by AKWolf · Aug 29, 2014 at 01:37 AM
Check out Remi Gillig's utility file for drawing debug objects https://gist.github.com/speps/3701541
Works great and no need to clutter your hierarchy with random debug game objects!
If you are looking to only draw something where the ray intersects an object, you can use those utility functions and pass in RaycastHit.point as the position. It is the world position of where the cast hit a specific collider.
http://docs.unity3d.com/ScriptReference/RaycastHit-point.html
Answer by AlwaysSunny · Aug 29, 2014 at 01:14 AM
Best way might be Graphics.DrawMesh()
Alternately, you could have an actual quad object you keep around, but only activate it when necessary.
Either method requires a texture and material of a red dot. You'd use hit.point to determine the quad's position in 3D space, probably backing it up by a small amount to avoid z-fighting.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161800im_/https://answers.unity.com/themes/thub/images/avi.jpg)