Combining functions from individual classes into 1 abstract class

My Moss Giant and my Spider maintain the same basic navigation function. I don’t want to rewrite it twice but I also want to make sure that if I need to customize my moss giant or spider, I can in their individual classes. We will now begin the process of combining logic from the moss giant that is shared into the main enemy class, leaving the individual specific scripts that inherit to customize the enemy.

First, let’s use a virtual method for movement. Let’s move our variables over from our moss giant to our enemy class.

I’m going to create a custom class that initalizes — or run’s as a start method.

And now I’m moving my functions over making sure that I add “public virtual” to my methods if I need to access them from my other script.

In our script that inherits, we need to make sure we don’t have a start or update method that overrides the abstract class on the enemy class.

Now the enemies will inherit the same behavior while inheriting a class.




Unity Developer and Software Engineer who loves making games with GameDevHQ

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

Recommended from Medium

First Launchpad Project of StarkNet Network: What is ZkPad?

Web URL Monitoring Using Zabbix

Amazon Maroc recrute Plusieurs Profils 2021

Method Swizzling: What, Why & How

Python Interview Questions You Need to Know to Become a Data Scientist — Part 1

Skills to pay the bills

The Ultimate Guide to Cloud Computing: A Simplified Overview

Building a serverless application using step functions, API Gateway, Lambda and S3 in AWS.

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
Al Heck

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ

More from Medium

What are the benefits of node. js ?

Ademir… Simple bank teller, or something more?

Playbill showing Ademir as The Enchanted Ronin

CS373 Spring 2022: Hrithik Ramganesh

GIVE UP the 9 to 5……Live ANYWHERE and JOIN the MILLIONAIRE Fastlane