Game Development Reference
//draw the paths in the scene view of the editor
Step 7. Play. With the 1 in 1000 chance of the guard going into
patrol mode, if you watch it for a while it will start moving from its
current location to the last waypoint. When it gets there it will go
into idle mode again, until after another 1 in 1000 chance it will
start to patrol back in the other direction. Note that as with the
waypoints in the previous workshop, the spheres may need to be
moved up so that the guard model doesn't sink into the floor.
Step 8. Select Assets > Import Package > Character Controller from the
main menu to add the First Person Controller prefab to the Project.
Step 9. Drag the First Person Controller prefab from the Project into the
Hierarchy. Delete the existing main camera, as the First Person Controller
has its own camera.
Step 10. Move the First Person Controller into the same room as the guard
so you can watch it moving.
Step 11. In the Hierarchy, shift-select all the polySurface submeshes
of the warehouse model and select Components > Physics > Mesh
Collider to add colliders to the warehouse. Without the colliders,
the First Person Controller will fall through the floor.
Step 12. Play. You will now be able to watch the guard patrolling from the
first person view.
Step 13. The guard model will seem dark as there is no directional light so
add one to the scene.
Step 14. Next we are going to add code to make the guard shoot and
chase the player. To do this, add pursue and attack states as shown
in Listing 5.11 .
Listing 5.11 Extending an FSM with More States
private var graph: Graph = new Graph();
private var prevState = "";
private var state = "idle";
private var event = "enter";
private var goalLocation: GameObject;