Game Development Reference
In-Depth Information
7. The last funcion of this script is the OnDrawGizmos() funcion, which will only
be used in the editor or debugging process. We will use this funcion to draw the
icon image, the radius, and the line direcion between each waypoint. Let's add
it as follows:
//Draw Gizmos and Directional line
public function OnDrawGizmos() : void {
//Get all Transform of this game objects include the children
and the transform of this gameobject
var waypointGizmos : Transform[] = gameObject.GetComponentsInChi
ldren.<Transform>();
if (waypointGizmos != null) {
if (orderDirection == true) {
//Draw line by the order of each waypoint 0,1,2,3,...
for (var i : int = 0; i < waypointGizmos.Length; i++) {
Gizmos.color = Color.red;
//Get the next way point
var n : int = (i + 1) % waypointGizmos.Length;
Gizmos.DrawLine(waypointGizmos[i].position,
waypointGizmos[n].position);
Gizmos.DrawIcon(waypointGizmos[i].position, iconName);
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(waypointGizmos[i].position, radius);
}
} else {
//Draw line from one point to every points except itself
for (var j : int = 0; j < waypointGizmos.Length; j++) {
for (var k : int = j; k < waypointGizmos.Length; k++) {
Gizmos.color = Color.red;
Gizmos.DrawLine(waypointGizmos[j].position,
waypointGizmos[k].position);
}
Gizmos.DrawIcon(waypointGizmos[j].position, iconName);
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(waypointGizmos[j].position, radius);
}
}
}
}
We use Gizmos.DrawLine() to draw the line between each waypoint, and
Gizmos.DrawIcon() to draw the icon image for each waypoint game object in
the scene to make it easier to edit. Then, we use Gizmos.DrawWireSphere()
to draw and calculate the area of each waypoint related to the radius .
 
Search WWH ::




Custom Search