Godot Version
4.6.1
Question
I’ve been trying to make enemies in my game but everytime the bullet hits them and their health reaches 0, they all get deleted instead of just one getting deleted. Could someone tell me how to fix this?
Enemy script
extends ColorRect
@onready var health: int = 100
@onready var damage: int = 20
func _ready():
Tracker.connect("hit", dealDamage)
func dealDamage():
health -= damage
if health < 0:
health = 0
if health == 0:
queue_free()
Bullet script
extends ColorRect
const SPEED: int = 800
func _process(delta: float):
position.x += SPEED * delta
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
func _on_area_2d_body_entered(body: Node2D):
Tracker.emit_signal(“hit”)
queue_free()