extends Camera3D

@onready var raycast : RayCast3D = $RayCast3D
var last_collided_object : CollisionObject3D = null

func _process(_delta : float) -> void:
	check_interaction()

func check_interaction() -> void:
	if raycast.is_colliding():
		var collider : CollisionObject3D = raycast.get_collider()
		if collider != last_collided_object:
			if last_collided_object != null:
				print("Stopped looking at interactable object:", last_collided_object.name)
				if last_collided_object.has_method("make_interactable"):
					last_collided_object.make_interactable(false)
			print("Started looking at interactable object:", collider.name)
			last_collided_object = collider
			if collider.has_method("make_interactable"):
				collider.make_interactable(true)
			
	else:
		if last_collided_object != null:
			print("Stopped looking at interactable object:", last_collided_object.name)
			if last_collided_object.has_method("make_interactable"):
				last_collided_object.make_interactable(false)
			last_collided_object = null
