Using the same health script for player and enemy,Using the same health script for player and enemies

So to optimize my game, I’m thinking of using the same health script for the player and the enemy. I followed the Survival Shooter tutorial and what they did was make a separate health script for the player and the enemy which is almost have the same code. I want to hear your practices. I don’t think there would be any problem with it. Is it viable or not?,Just starting a new project, and I’m new to Unity development as well. So I was thinking, to optimize my game, I’m planning to use the same health script for my player and enemy. Because the same kind of damages would hit a player and an enemy so I think having a quite powerful script that handles the health of all the character that I need would be nice. I want to hear your practice on how you do this. I followed the Survival Shooter tutorial on Youtube and what they did was make 2 separate health script for the player and the enemies which is mostly the same.

In an earlier unfinished game I gave up on, I used the same “CharacterScript” for all “living things” with variables for health, stamina, movement speed, endurance (how long they can move in one direction before they get tired and have to rest) and a variety of other things. With simple methods such as “processDamage” “increaseHealth” and such. The only difference was NPC’s had a separate script attached for utilizing the first script, where the player had a script for getting their input.
I’ve learned to “compartmentalize” better, but there’s no reason why it wouldn’t work, just keep in mind to make it as generalized as you can.
IE: if you want a certain type of enemy to not be able to be damaged by the player.