Handling user input

The event that gets called when the user presses an answer button on the UI is OnAnswerSubmitted. The method is quite simple and is only a few lines of code:

public void OnAnswerSubmitted(int answerIndex) {    answerTotal += questions[questionIndex].answers[answerIndex].moralityValue;    questionIndex++;    LoadQuestion(questionIndex);}

The method does a few things:

  • It aggregates the answer value to the answer total. We'll look at how these values are assigned up ahead.
  • It increments the question index value.
  • Finally, it calls LoadQuestion with the incremented index value from the previous bullet.

Get Unity 2017 Game AI Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.