In my game, I currently have multiple types of bullets (that do different amounts of damage) and multiple enemies (that have different amounts of health). What’s the best way to implement enemies taking damage from the bullets? I’m trying to make my code as clean as possible.
Currently the way I see it is for each enemy, have a long if/else statement checking the type of bullet that the enemy was struck by, and removing a certain amount of health based on that, but that seems messy and redundant because each bullet should do the same amount of damage to each enemy.
Ideally, I imagine each bullet checking in its onCollision whether the object it struck had the “Enemy” tag, and if so, call some method removeHealth(float damage) for example on that game object. However, each of my enemies are currently in a different script so I don’t think I can blindly call a removeHealth method on the target.
Is there a better way to implement this? Thanks.