This is my enemy script :
var direction=1
var is_dead=false
export(int) var hp=10
func _ready() -> void:
pass # Replace with function body.
func dead():
hp-=1
if hp<=0:
is_dead=true
velocity=Vector2(0,0)
$AnimatedSprite.play("Dead")
$CollisionShape2D.disabled=true
$Timer.start()
func _physics_process(delta):
if is_dead==false:
velocity.x=SPEED*direction
if direction == 1:
$AnimatedSprite.flip_h=false
else:
$AnimatedSprite.flip_h=true
$AnimatedSprite.play("Corona")
velocity.y+=GRAVITY
velocity=move_and_slide(velocity, FLOOR)
if is_on_wall():
direction=direction*-1
$RayCast2D.position.x*=-1
if $RayCast2D.is_colliding()==false:
direction=direction*-1
$RayCast2D.position.x*=-1
if get_slide_count()>0:
for i in range(get_slide_count()):
if "Player" in get_slide_collision(i).collider.name:
get_slide_collision(i).collider.dead()
func _on_Timer_timeout() -> void:
queue_free()
and this is my script for Progress Bar which appears on top of my Enemy :
extends ProgressBar
func _ready():
pass
func _physics_process(delta):
value=get_tree().root.get_node("World").get_node("Enemy").hp
All this is fine but I want to make multiple copies of my same enemy for my game stage ! Simply copying over the Enemy node isn't giving me desired results as the enemies do appear and can be destroyed too but their life bar doesn't change and stays full except the one enemy from which all others were copied. That's probably because the copies have numbers added to their names like enemy1,enemy2 and so on and I must change the name in progress bar script. But If I change the name of node there than still the issue prevails because now let's say that enemy1 is working as desired but enemy is showing full life bar. Is there any way I can make copies of enemy and make the life bar interact with each of them separately and not simultaneously