Step 4: Finishing The Scene
Apply the navigation script to your cylinder and set the values of its variables in the inspector. The X and Z values will correspond to the size of your floor. For a 15 scale plane, the min and max is 75.
Going forward, we’ll need to organize the cylinder and its goal into one group. Do this by creating an empty game object named “NPC” and dragging the cylinder as its child. Next create a sphere game object, change its color, and drag it in the hierarchy so that it is a child of the NPC object likewise. Once you’ve done that, change the sphere’s name to “goal” and drag it to the Goal variable located in your cylinder’s inspector within the Navigation script component. Doing so will allow this goal object to be moved by the Navigation script, triggering a new destination for the AI. At this point your AI is fully functioning, but we’re still not quite done.
In the inspector, select the goal object and under layer select UI.
Next select the main camera and under culling mask deselect UI. Doing so will prevent you from viewing the goal object once the game starts but still allow you to track them in the scene view you’re seeing now.
Now that your NPC is completed create a folder called prefabs. Drag the entire NPC group from the hierarchy to this new folder. Now you can drag from this NPC prefab into the scene itself to clone new NPCs. You can also edit variables within the NPC prefab itself by selecting the navigation script component attached to the cylinder to have the changes propagate to all the instances of NPCs you’ve created in the game.
Clone as many NPCs as you desire, drag the main camera to the positioning of your choice, and hit play. The scene is now completed. If you would prefer a more personal view, you may set the camera as a child of a NPC cylinder of your choice to follow that NPC around the map.