what is the best way to set up a health and damage system. I have 2 weapons available in my game called flak cannon(15 damage) and plasma cannon(5 damage). I have no idea how to get the health of other game objects and take the required amount away when the projectiles collide with them.
From a design perspective I recommend encapsulate the values within each object. What I mean is that weapons will know how much damage they do and the enemy know how much health it has.
For example you can have WeaponScript that contain a tunable member called weaponDamage. You can set it in the editor and can be 15 for flack and 5 for plasma.
There is a separate script for enemy that contain a values called health. The EnemyScript also expose a method called something like AddDamage(float ammountOfDamage)
When the weapon hit an enemy it calls EnemyScript.AddDamage(weaponDamage);
In the enemy script you decrement the health by the damage amount and if below zero you kill the enemy.
So the weapon does not need to know anything about the enemy health or what to do with it. It just tell the enemy I did you X damage.
The enemy does not know anything about the weapon, it’s just told you received this damage and handle the rest.