Game Development Reference
In-Depth Information
OnDrawGizmos()
Implement the
OnDrawGizmos()
function if you want to draw gizmos that are also pick-
able and always drawn. This allows you to quickly pick important objects in your scene.
You can also use
OnDrawGizmos()
to draw a line or different type of gizmos, such as
Gizmos.DrawRay
,
Gizmos.DrawLine
, and
Gizmos.DrawWireSphere
, which
will make it easier for you to debug the code.
Tip
OnDrawGizmos()
will use a mouse position that is relative to the
Scene
view. This func-
tion only works for debugging in the editor.
An example of
OnDrawGizmos()
is as follows:
// JavaScript user:
var target : Transform;
// Draw the blue line from this object to the target
function OnDrawGizmos () {
if (target != null) {
Gizmos.color = Color.Blue;
Gizmos.DrawLine(transform.position, target.position);
}
}
// C# user:
Transform target;
// Draw the blue line from this object to the target
void OnDrawGizmos () {
if (target != null) {
Gizmos.color = Color.Blue;
Gizmos.DrawLine(transform.position, target.position);
}
}