Book Image

Creating E-Learning Games with Unity

By : David Horachek
Book Image

Creating E-Learning Games with Unity

By: David Horachek

Overview of this book

Table of Contents (17 chapters)
Creating E-Learning Games with Unity
About the Author
About the Reviewers

Creating the NPC GameObject

To develop and test our NPC systems, we need a simple Prefab to represent our NPC character. Once this is working, we will be able to add polish to the game by replacing it with a more visually appealing model and by adding animation. To begin with, create a capsule with a scaled hat similar to the player Prefab placeholder.

Implementing the npcScript class

The npcScript class will encode the base state machine for NPCs. To develop a robust non-player character system requires a model of the behavior we want to present to the player. Once we have a model, we can build an FSM that meets our functional needs. We shall list these requirements in the following part.

In our e-learning game, the non-player characters will need to do the following:

  • Travel about the world in a smooth, realistic way

  • When approached by the player, the NPC should stop and face the player to interact

  • When the player leaves the NPC or finishes the interaction, it should continue moving about the...