Scripting our non-player characters
In this section, we will write the necessary scripts to manage the Cucumber Beetles in our game. Specifically, we will write scripts to accomplish the following:
- Beetle patrol
- Beetle finds and eats cucumber
- Beetle attacks player on the ground
- Beetle stands to attack
Getting organized
Since we are writing several scripts, we should stay organized. We can click Favorites | All Scripts in the Project panel to get a list of all the scripts in our project, but there are a lot of them, most of which we will not edit for our game. So, let's create a folder in the Project panel to organize our custom scripts. Here are the steps:
- In the
Projectpanel, right-click theAssetsfolder - Select
Create|Folder - Name the new folder
Custom Scripts
Now that we have a folder for our custom scripts, let's move a few:
- In the
Projectpanel, clickFavorites|All Scripts. - Scroll until you find the
BeetleNPCscript we created earlier in this chapter. - Drag the
BeetleNPCscript to ourCustom...