We've now configured the zombie to display the selected word, and also to add text stylizations based on player input. However, we still haven't linked player input through the Typer
class (coded in the previous chapter) with the zombie NPC. Let's do this now by adding a new function to the EnemyAI
class, namely UpdateTypedWord
. This function compares the typed word with the associated word to determine the extent of a match. The purpose is twofold, firstly, to generate the MatchedWord
string, for highlighting the typed portion of the Associated Word
; and secondly, to fire a word matched event (OnTypingMatched
), which causes the zombie to die. Consider the following code:
//------------------------------------ public void UpdateTypedWord() { //If not chasing or attacking, then ignore if(ActiveState != AISTATE.CHASE && ActiveState != AISTATE.ATTACK) return; MatchedWord = WordList.CompareWords...