20 lines
466 B
GDScript3
20 lines
466 B
GDScript3
|
|
extends Area2D
|
||
|
|
|
||
|
|
signal collected(collector: Node2D)
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
self.body_entered.connect(_on_collected)
|
||
|
|
self.area_entered.connect(_on_collected)
|
||
|
|
|
||
|
|
func _on_collected(collection: Node2D) -> void:
|
||
|
|
var collector := collection.owner
|
||
|
|
if collector == null:
|
||
|
|
return
|
||
|
|
|
||
|
|
## 如果收集者存在收集接口,那麽就把自己傳過去
|
||
|
|
if collector.has_method("collect_item"):
|
||
|
|
collector.collect_item(self)
|
||
|
|
collected.emit(collector)
|
||
|
|
|
||
|
|
self.queue_free()
|