Topic was automatically imported from the old Question2Answer platform.
Asked By
ahmedKH
i made this spawner code:`
func _on_spawntime_timeout() -> void:
var px = rand_range(1000 ,0)
var py = rand_range(0,1000)
var loc = Vector2(px,py)
var e = enemy.instance()
add_child(e)
e.position = loc
i want the enemy instance same as enemy scene like if i change the damge from the main scene it will change for both enemy instance and the orginal enemy
func _on_hitbox_body_entered(body: Node) -> void:
if "bullet" in body.name:
$enemyhealthbar.value -= dmg
Make a setter function for the variable.
When you will need to change the variable value, just call it and it will set dmg variable in all of your instances.
Create a list with all of your instances, then in the setter function for each of the enemies set dmg in each of them.
If i understanded your logic, the best way is put the enemies in a array or something and create a logic to set the value in the elements of array. Also you can script a foreach with scene children and identify the enemy by some method with has_method.
If you want a more automatic logic you can create a signal in the main scene that triggers every time that the damange is calculated and connect that signal in the enemies.