extends Node2D signal scored() var spawn_positions = null var enemy = preload("res://Scenes/enemy_xwing.tscn") func _ready(): randomize() spawn_positions = $SpawnPositions.get_children() func spawn_enemy(): var index = randi() % spawn_positions.size() var enemy = enemy.instantiate() enemy.global_position = spawn_positions[index].global_position #connect error. unsure why. #enemy.connect("enemy_died", get_tree().current_scene, "scored") add_child(enemy) #AI Generated code, doesn't work. connect error #func spawn_enemy(): #var index = randi() % spawn_positions.size() #var enemy_instance = enemy.instantiate() #var world_node = get_node("res://Scenes/world.tscn") #var world_script = world_node.get_script() #enemy_instance.connect("enemy_died", world_script, 10) #enemy_instance.global_position = spawn_positions[index].global_position #add_child(enemy_instance) func _on_spawn_timer_timeout(): spawn_enemy() func enemy_died(): emit_signal("scored") func missile_spawn(): print("Missile")