Class Under a Class- Game Dev Series 134

Objective: create custom class that inheritance from another class.

Photo by Henry Hustava on Unsplash

We have used interface in the past articles. In this tutorial, we would create a quite similar function but not exactly the same. We would inheritance from a custom class.
When would this function be common in game? As we did in the last article, this would be the main part of an RPG game. This time we would go deeper to separate different type of item in RPG game with this function.

Inheritance from item

We have created an Item script as base data to create an item. However, we might have some weapons and some foods in inventory of Player. The data of these items would not possible to be the same. That is a good time to inheritance from Item.

Create a script called Weapon, and removing the MonoBehaviour but adding Item this time.

Now we can declare what data should a weapon has.

Then make it serializable to be available to adjust in Inspector.

And with same setting, let’s create another class called Eatable.

Now we can add these type of items into our database.

Complete data of an item

Open ShopDatabase script, and create an array to both Weapon and Eatable.

Now if we add some new items, weapons, or eatables in game, we can see the specific data column of that type of item, which would contain some data from script Item.

As you can see it is not just reveal the data we created for both type of item, but also inheritance the base data from Item.
And that would be easier for you to create lots of unique and sortable items.




A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

ImpOsm2pgRouting: Route planning on OpenStreetMap road network with the benefit of updates

My Top Software Tools from 2017

How to Create Fully Functional E-commerce Website With Django

Everything to know about GSoC!

Best practice : REST API Resource Naming

Powered By :

Golang Development Setup

Consuming with RESTful APIs with Vertx HttpClient/WebClient

Getting to Know Terraform

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Unity C#: Static

Building a Modular Ducking System

Scripting Actions (New Unity Input System)

Virtual Cameras w/ Cinemachine in Unity 2020 — Part 4