Shooting and taking damage.

Hello!
This is guess is quite a bit odd question but i really need some help here!
Whats the best way to shoot and take damage?

EX:
Enemy has a life property, i want to ray it and depending on a property(actual weapon damage) i want to decrease the life of the enemy.

Enemy - Life [100]
Player - weapon_damage[25]
If fire rayed enemy Life -= weapon damage.

Any suggestions?

You’re best off using raycasts.
Use the idea of multipliers

Get the hit object.
Determine if it has health, if not don’t do anything (e.g return from a function)
Have a damage constant, like 1.0 and multiply it by the weapon damage constant, which could be 1.5
Subtract that value from the enemies health.
Set the health on the enemy

Yes, i could do it, but if multiple enemies on the screen, how do i decrease the life of the enemy that i am raying? I need somehow to determine which is the current enemy that is rayed, i have no idea.

use RayCastTo

object.rayCastTo(other_object, distance, property)

where object and other_object are GameObjects respectively,
and distance set to a range (int or float)
and property can be set to only trigger if an object with a certain property is hit.

Found another way:
hitObject = ray.hitObject

if fire and hitObject[‘health’]:
ray.hitObject[‘health’] -= 15 (or my current weapon) , yes it works, tested it!