Game Development Reference
In-Depth Information
gos = GameObject.FindGameObjectsWithTag ("waypoint");
for (var go : GameObject in gos)
{
graph.AddNode(go, true, true);
}
CreateBiPath("Sphere3","Sphere2");
CreateBiPath("Sphere2","Sphere1");
CreateBiPath("Sphere1","Sphere4");
CreateBiPath("Sphere3","Sphere4");
CreateBiPath("Sphere4","Sphere5");
CreateBiPath("Sphere5","Sphere6");
CreateBiPath("Sphere6","Sphere7");
CreateBiPath("Sphere7","Sphere8");
CreateBiPath("Sphere8","Sphere9");
CreateBiPath("Sphere9","Sphere10");
CreateBiPath("Sphere10","Sphere11");
CreateBiPath("Sphere11","Sphere12");
CreateBiPath("Sphere12","Sphere13");
CreateBiPath("Sphere13","Sphere14");
CreateBiPath("Sphere14","Sphere15");
CreateBiPath("Sphere15","Sphere17");
currentNode = GameObject.Find("Sphere2");
}
function Update()
{
//draw the paths in the scene view of the editor
//while playing
graph.debugDraw();
}
Step 4. Play. Go into the Scene view and have a look at the paths that
have been created. In this code, a function has been written to help take
away part of the laborious job of programming which points connect
by creating bidirectional paths. This code also populates the waypoint
graph automatically by looking for all the spheres that were tagged with
waypoint in the Start() function.
Step 5. Locate Sphere2 and place the guard model near it as it
has been set as the initial value for currentNode and will be used as
the starting location of guard. Alternatively, you could add
code such as this.transform.position = currentNode
.transform.position to the end of the Start() function
to have the code place the model.
Step 6. Modify the patrol script to that in Listing 5.10 .
Search Nedrilad ::




Custom Search