In the enemy script add the function to take damage:
func take_damage(damage_amount):
damage -= damage_amount
if damage < 1:
initiate_death()
Declare the initiate death function in the same enemy script:
func initiate_death():
queue_free()
Then in bullet script, declare bullet damage amount and a hit function:
var damage_amount = 10
func hit(body):
if body.has_method("take_damage"):
body.take_damage(damage_amount)
Also make sure to connect body_entered
signal to the hit function in _ready()
function.
func _ready():
connect("body_entered", self, "hit")
I have assumed you are using godot 3 since you didn't specify which version you are using. If you are using godot 4 and have problems converting the code just comment on this answer.