2024-07-09 22:33:38 +02:00
|
|
|
@tool
|
|
|
|
class_name PickupItem
|
|
|
|
extends Node3D
|
|
|
|
|
2024-08-15 23:43:05 +02:00
|
|
|
signal item_picked_up(node_path:NodePath)
|
|
|
|
|
2024-09-27 11:46:31 +02:00
|
|
|
@onready var world_item_node = %WorldItemNode
|
|
|
|
|
2024-07-09 22:33:38 +02:00
|
|
|
@export var item:Item:
|
|
|
|
get:
|
|
|
|
return item
|
|
|
|
set(value):
|
|
|
|
if value != item:
|
|
|
|
item = value
|
|
|
|
|
2024-09-27 11:46:31 +02:00
|
|
|
if not Engine.is_editor_hint() or world_item_node == null:
|
|
|
|
return
|
2024-08-15 21:13:09 +02:00
|
|
|
|
2024-09-27 11:46:31 +02:00
|
|
|
for child in world_item_node.get_children():
|
|
|
|
child.get_parent().remove_child(child)
|
|
|
|
child.queue_free()
|
|
|
|
|
|
|
|
world_item_node.add_child(item.scene.instantiate())
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-09-27 11:46:31 +02:00
|
|
|
if item == null:
|
|
|
|
push_error ("Error: invalid PickupItem at %s" % str(global_position))
|
|
|
|
return
|
|
|
|
|
2024-07-09 22:33:38 +02:00
|
|
|
var item_scene = item.scene.instantiate()
|
2024-09-27 11:46:31 +02:00
|
|
|
world_item_node.add_child(item_scene)
|
2024-07-09 22:33:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_area_3d_body_entered(body):
|
|
|
|
if body.has_method("on_item_picked_up"):
|
|
|
|
body.on_item_picked_up(item)
|
2024-10-11 18:40:40 +02:00
|
|
|
item_picked_up.emit(get_path())
|
2024-07-09 22:33:38 +02:00
|
|
|
queue_free()
|