Creating Your First Enemy

The player can run and jump and fall down pits, but they’re probably going to need more of a challenge—and more variety—than that. Let’s add a Slime enemy to the world that the player must avoid. We’ll give it a classic “shambler” Artificial Intelligence, or AI; it will walk in one direction until it encounters a wall, at which point it will turn around and head the other way. It will also change direction if it collides with another enemy of its kind.

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.