Optimizing scripts

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

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.