Unity games run several frames per second and many of our scripts are executed each frame. Even uncomplicated games, such as the Cucumber Man, can have several scripts running every frame, causing the computer's CPU to stay very busy. The goal is to ensure our scripts are not causing any unnecessary CPU load.
Our game has 145 scripts, but most of them are part of the standard asset package and are not assigned to any game objects. The scripts we want to review are the ones we put in the Assets
| Custom Scripts
folder. Reviewing that folder reveals that there are only 14 scripts:
- BeetleManager
- BeetleNPC
- BeetlePatrol
- CameraFollower
- CherryControl
- CherryManager
- CucumberManager
- CucumberManManager
- HealthManager
- PlayerController
- PlayerMotor
- PointsManager
- ThrowCherry
- VictoryManager
Our goal is to reduce the number of instructions the CPU has to execute, especially when we are dealing with several executions per frame and multiple frames per second. Here are some things to check when reviewing...