Game Development Reference
In-Depth Information
Implementing the npcDecisionMgr script
This class is the brain of the NPC. It contains a collection of the interactions that are
constantly evaluated. If any condition is determined to be true , the appropriate re-
sponse is dispatched. To construct it, we need to perform the following steps:
1. Create a new script named npcDecisionMgr .
2. As with npcInteraction , edit the class declaration to remove the inherit-
ance from MonoBehaviour , and add explicit serialization so that the class
data can be saved in the editor:
[System.Serializable]
public class npcDecisionMgr{
3. A public list of npcInteraction is exposed to the inspector. In here, a col-
lection of condition/response pairs can be added for later evaluation. In this
way, a whole set of logical interactions can be added to a character—all from
within the editor!
public List<NpcInteraction> interactions;
4. The eval() method is used to visit each NPC interaction in the list, where
each one is evaluated in turn; recall this checks the condition.eval()
method for the condition member of the interaction:
foreach (npcInteraction e in interactions)
{
e.eval();
}
Congratulations! You have completed writing the DecisionMgr class for the NPC.
This is the class that will contain all of the logic for the NPC—what it will query in the
world, and how it will respond to those queries.
Search WWH ::




Custom Search