extends Area3D

@export var item_name: String
@onready var itemToInstantiate = preload("res://Scenes/pickup.tscn")

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

func _physics_process(delta: float) -> void:	
	var overlapping_bodies = get_overlapping_bodies()
	for body in overlapping_bodies:
		if body.is_in_group("item") or body.is_in_group("canTriggerSwitch"):
			print("test")
			var key = itemToInstantiate.instantiate()
			key.item_name = item_name
			key.global_position = $SpawnLocation.global_position
			$"..".add_child.call_deferred(key)
			queue_free()
			break;
	
#func _on_area_3d_body_entered(body: Node3D) -> void:
#	print(body)
#		
