Scripting the Enemy Slime Component

We’ve created our EnemyController script, but we won’t be adding it directly to anything. Instead, we’re going to create a script that will inherit from it as well as have its own code:

1. Select the enemySlime GameObject.

2. Click the Add Component button and choose New Script.

3. Name the script “EnemySlime” and ensure that the language is set to CSharp.

4. In the Project Browser, select the newly created script and move it to the _scripts folder.

5. Double-click the script to open it in MonoDevelop-Unity.

Clear the base Start() and Update() functions out of the script. For the moment, just adjust the script to match Listing 9.2.

Listing 9.2 The EnemySlime Script Inheritance

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.