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
Project
panel, right-click theAssets
folder - 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
Project
panel, clickFavorites
|All Scripts
. - Scroll until you find the
BeetleNPC
script we created earlier in this chapter. - Drag the
BeetleNPC
script to ourCustom...