Inheritance and the EnemyController Component

Normally we’d create and add a controller script to our enemy at this time, but we’re going to touch on class inheritance here as it applies to creature creation.

Enemies could easily share certain properties, such as having health, a score value, or specific flags. They may also use some of the same script functions. Rather than recreate these elements in every unique enemy controller script, we’re going to create a core script from which they can be inherited:

1. Navigate to the _scripts directory in the Project View.

2. Right-click and select Create > C# Script.

3. Name the new script “EnemyController.”

We’re going to put very little into the script because the mechanics behind the game are simple, ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation 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.