extends Node

export var coin_scene : PackedScene

export var all_coins_picked_up_script : Resource

var coins := -1

func spawn():
	if coins < 0: # not spawned yet
		coins = 0
		for spawn in get_children():
			var coin = coin_scene.instance()
			coin.connect("picked_up", self, "on_coin_picked_up")
			coins += 1
			spawn.add_child(coin)

func on_coin_picked_up():
	coins -= 1
	if coins == 0:
		EventDispatcher.emit_signal("trigger_script", all_coins_picked_up_script)
