The morality meter example
The faction/morality meter example for this chapter covers a slightly different approach to implementing fuzzy logic via Unity. We build upon the implementation we covered in the basic fuzzy logic example.
In this example, we create a simple dialogue sequence, where the player is presented a series of scenarios, or questions, that they can then answer according to their morality. For simplicity's sake, we've included a "good," "neutral," and "evil" answer for each question. Let's take a look at the code to understand this a bit better.
The question and answer classes
The Question
and Answer
classes are very simple, and are used as data containers. Let's look at the Question.cs
class first:
[System.Serializable] public class Question { public string questionText; public Answer[] answers; }
Note
You may have noticed that the Question
class does not derive from MonoBehaviour
. It is a plain ol' vanilla C# class. As such, Unity will not serialize it by default...