Skip to main content
2 of 2
There is no engine called "Unity2D". It's just Unity. Class inheritance and composition does not behave differently in 2D than in 3D games.; deleted 22 characters in body
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

How to program different types of monsters

I'm working with a group of programmers and I'm trying to program different types of monsters in Unity. I want to make it so that all the monsters have values like attack power, attack speed, moving speed, etc, and basic functions like attack or walk.

Normally, if I wanted to do this in Java, I would just create one class called Monster and make child classes for each of the different types, but I'm not sure how to do this in Unity, since Unity c# uses Monobehavior and you have to attach scripts to a game object.

To go into more detail, I want to instantiate different monster types at random. I would have prefabs like slime, skeleton, etc with their corresponding scripts, and instantiate them randomly. And for each of these instantiated monsters, I want them to immediately move and attack according to its type's (slime, skeleton, ...) attack speed, attack power, etc.

How could I achieve this? As in, how would professional game developers organize their code in this situation? I'm looking for basic directions like: create this class, attach this script to this prefab, etc; I could look up the details on my own, and I just need simple guidelines.

UserUser
  • 171
  • 1
  • 11