Day 112 — Designing Enemies using Abstract Classes

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
protected int health;
protected int speed;
protected int gems;
public virtual void Attack()
{
Debug.Log("Enemy Attack");
}
}
public class MossGiant : Enemy
{
void Start()
{
Attack();
}
}
public class Spider : Enemy
{
void Start()
{
Attack();
}
public override void Attack()
{
Debug.Log("Spider Attack");
}
}

Abstract Class

public abstract class Enemy : MonoBehaviour
{
protected int health;
protected int speed;
protected int gems;
public virtual void Attack()
{
Debug.Log("Enemy Attack");
}
public abstract void Update();
}
public override void Update()
{
Debug.Log("Updating the Moss Giant...");
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kubernetes

5 Salient Aspects to Keep in Mind while Defining Retention Period for Database Backups

Linked Lists in C

How to remove HTML from a text string in Python

IEC 62304: Medical Device Software LifeCycle Processes

Auto buy products from amazon in just 10 lines of python code

Quick Guide to Latex for Homework

How to detect OOMKilled containers on the GKE environment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

Managers, Main Menu and Loading screen

Unity use right stick to aim in 2D with new input system

Learn to code by making 2.5 D Space Shooter

Hidden Shortcuts to Make Level Design Easier in Unity.