Calculating the results

Finally, we have the EndConversation method, which, as we saw, gets called when we have answered all the questions (and the question index is out of bounds, based on our questions[] array length).

The first line simply disables the panel game object containing the question UI:

questionPanel.SetActive(false);

The calculations are in the next block of code:

 float average = answerTotal / questions.Length; float goodRating = good.Evaluate(average); float neutralRating = neutral.Evaluate(average); float evilRating = evil.Evaluate(average);

We calculate the average of all of our answers by taking the answerTotal value (the sum of all the answers) and dividing it by the number of questions. We then individually evaluate ...

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.