30 lines
700 B
GDScript
30 lines
700 B
GDScript
extends Area3D
|
|
|
|
var available : Array[Node3D]
|
|
|
|
func activate_first():
|
|
if available.is_empty():
|
|
return
|
|
for object in available:
|
|
if object.can_interact():
|
|
if object.has_method("interact"):
|
|
object.interact()
|
|
if object.is_in_group("WeaponPickup"):
|
|
owner.equip_weapon(object)
|
|
return
|
|
|
|
func _area_entered(node : Node3D):
|
|
if node.is_in_group("Interactive"):
|
|
available.push_front(node)
|
|
|
|
func _area_exited(node : Node3D):
|
|
available.erase(node)
|
|
|
|
func _ready():
|
|
area_entered.connect(_area_entered)
|
|
area_exited.connect(_area_exited)
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("activate"):
|
|
activate_first()
|
|
get_viewport().set_input_as_handled()
|