So I’m designing a (currently basic) combat system for a 2D exploration/platformer game kinda like a Metroidvania of sorts, and I’m somewhat confused as to how to make it work in terms of how to handle enemy health values. Is it a good idea to hook them all up to a global script that manages each enemy’s health individually? I’m using serialized fields to be able to change each entity’s value in-engine, but I’m not totally sure how good of an idea that is. It’s one I came up with to avoid having to make separate scripts for every single enemy type in the game, and I can simply use inheritance or some other method to link it with boss scripts that work differently, but I’m not totally sure if this is even a good idea. Maybe I’m just being an idiot?
Why not create a Health component and add it to all gameobjects that have health?
Maybe im not understanding your issue…?
That’s… not the question, that’s basically what I’m doing right now. What I’m doing right now is I created a C# script with serialized variables, which I called GlobalEnemyHealth, and am assigning that to any instance of an enemy GameObject, the player’s being tracked separately and displayed on the game HUD. I’m just not sure if that’s how I SHOULD be doing it is the thing.
If the health only changes when a collision occurs then it doesn’t really matter which method you use. A health component is probably easier to work with and more in line with the Unity way. But if the health constantly regenerates over time and you have 1000s of enemies then it’ll be faster to iterate over all those health values if they’re all stored in an array in a single script.