extends Area3D

static var total_exits: int = 0
static var found_exits: int = 0
var exit_found: bool = false

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	total_exits += 1


func _physics_process(delta: float) -> void:
	var on_exit = false
	var overlapping_bodies = get_overlapping_bodies()
	for body in overlapping_bodies:
		if body.is_in_group("player"):
			on_exit = true
			break;
			
	if on_exit:
		if !exit_found:
			exit_found = true
			found_exits += 1
			if found_exits >= total_exits:
				print("You finished the level!")
				if (WholePlayer.getNextStage):
					get_tree().change_scene_to_file(WholePlayer.getNextStage)
			else:
				print("Found an exit! ", found_exits, " out of ", total_exits)
	else:
		if exit_found:
			exit_found = false
			found_exits -= 1
			print("Left an exit")
