All gizmo drawing needs to be done in the script's Ondrawgizmos or ondrawgizmosselected function.
Ondrawgizmos is called at each frame. All the gizmos that are rendered in Ondrawgizmos are visible.
Ondrawgizmosselected is called only if the object attached to the script is selected.
Gizmos.drawline
Draw a line from obj1 to Obj2.
Using unityengine;using System.collections;public class Drawlinetext:monobehaviour {public Gameobject obj1; Public Gameobject Obj2; void Ondrawgizmos () {gizmos.color = Color.green; Gizmos.drawline (Obj1.transform.position, obj2.transform.position); }}
2.gizmos.drawray
Draw a 10-length ray from obj
Using unityengine;using System.collections;public class Drawraytext:monobehaviour {public Gameobject obj; void Ondrawgizmos () {gizmos.color = Color.gray; Gizmos.drawray (obj.transform.position, Vector3.up * 10); 10 is the length}}
3.gizmos.drawcube
Draw A (1,1,1)-sized cube at (0,1,0)
Using unityengine;using System.collections;public class Drawcubetext:monobehaviour {void Ondrawgizmos () { Gizmos.color = color.red; Gizmos.drawcube (Vector3.up, Vector3.one); }}
4.gizmos.drawicon
Generate an icon named 002imgzlzy6mro7r94ka2&690.jpg at (0,0,0), which will be placed in the Gizmos folder under assets.
Using unityengine;using System.collections;public class Drawicontext:monobehaviour {void Ondrawgizmos () { Gizmos.drawicon (Vector3.zero, "002imgzlzy6mro7r94ka2&690.jpg"); }}
This article is from the "Sea Know Sleepless" blog, please be sure to keep this source http://745559847.blog.51cto.com/11658719/1891989
C # Unity Gizmos visual aids