Godot Version
4.5
Question
Hello! Im trying to make a interactable 3d object in my game ![]()
with this code, its giving me the error “Error at (10, 16): Identifier “current_interations” not declared in the current scope.” But its identified only a few lines before?
Im very new to godot im sorry :,D
extends Node3D
@onready var interact_label: Label = $Label
var current_interactions := []
var can_interact := true
func _input(event: InputEvent) -> void:
if event.is_action_pressed("interact") and can_interact:
if current_interations:
can_interact = false
interact_label.hide()
await current_interactions[0].interact.call()
can_interact = true
func _process(_delta: float) -> void:
if current_interactions and can_interact:
current_interactions.sort_custom(_sort_by_nearest)
if current_interactions[0].is_interactable:
interact_label.text = current_interactions[0].interact_name
else:
interact_label.hide()
func _sort_by_nearest(area1, area2):
var area1_dist = global_position.distance_to(area1.global_position)
var area2_dist = global_position.distance_to(area2.global_position)
return area1_dist < area2_dist
func _on_area_3d_area_entered(area: Area3D) -> void:
current_interactions.push_back(area)
func _on_area_3d_area_exited(area: Area3D) -> void:
current_interactions.erase(area)