Menu
CoddyTech

Enemy Types

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 51 of 64.

challenge icon

Challenge

Medium

Add two kinds of enemy on one abstract base.

  1. Make Enemy abstract. Each frame it passes the way to the hero, y set to 0, to protected abstract void Move(Vector3 toHero);.
  2. Grunt : Enemy overrides Move: walk at the hero at speed, stopping within 1 unit.
  3. Dasher : Enemy rests restTime, dashes dashTime at speed toward where the hero was, and repeats.

Press Play and dodge them. Then Check.

Try it yourself

using UnityEngine;

public class Enemy : MonoBehaviour
{
    // [SerializeField] lets the Inspector set a protected field too.
    [SerializeField] protected float speed = 2f;

    // A later lesson fills this in: what every enemy has in common.
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground