Game Development Reference
In-Depth Information
Creating the FlagMonument GameObject
Let's build the geometric structure that will be the focal point of the first mission—the
monument that needs the flags returned by performing the following steps:
1. Create a new Cube GameObject. Scale it so that it is a long and narrow rect-
angle on the ground in a central place. Name this monument.
2. Create five short Cylinder GameObjects. Name them FlagMount1 to
FlagMount5 , and parent them to the monument so that they are on top of
the monument.
3. This should look very similar to the FlagLocators in the Hierarchy pane
seen previously, but we will also create a MonumentMgr class and extend its
functionality.
Creating the MonumentMgr Script
This script provides the API for the inventory to attach items to the flag mounts at the
conclusion of the level.
The InventoryMgr script that we will write in this chapter, will use the methods
provided in the MonumentMgr script to do this work by performing the following
steps:
1. Create a new script, and name it MonumentMgr.cs . Attach an instance of it
to the monument GameObject .
2. Inside the script, add public List<GameObject> to store the mount
points as shown in the following code. Don't forget to add using Sys-
tem.Collections.Generic to the top of the file so that we can declare
list properties. Failure to add this line of code will result in compile time errors
in your script:
public List<GameObject> mountPoints;
3. Drag-and-drop the individual flag mount points from the monument to this list.
4. We add an attachObjToMountPoint(GameObject obj, int index)
public method as shown in the following code. We first create an instance or
clone of the object passed in, attach the object to the given mountpoint ,
and then zero its local translation and rotation. Doing this forces the object to
Search WWH ::




Custom Search