Book Image

Mastering Unity 5.x

By : Alan Thorn
Book Image

Mastering Unity 5.x

By: Alan Thorn

Overview of this book

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.
Table of Contents (16 chapters)
Mastering Unity 5.x
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Zombies and the Typer class


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...