Use this script on a pickup object (Area3D) or collectable. This will add a score (assuming the player has a method called add_score.
extends Area3D # Change to Area2D if you are making a 2D game
@export var score_value: int = 1
func _ready() -> void:
# Connect the signal dynamically if you haven't done it in the editor
body_entered.connect(_on_body_entered)
func _on_body_entered(body: Node3D) -> void: # Change to Node2D for 2D
# Check if the colliding body is the player
if body.is_in_group("player"):
collect(body)
func collect(player: Node3D) -> void:
# 1. Update the player's stats or inventory
if player.has_method("add_score"):
player.add_score(score_value)
# 2. (Optional) Play a sound effect or spawn particles here
# AudioServer or a global AudioManager is ideal so the sound
# doesn't cut off when the item is deleted.
# 3. Remove the item from the world
queue_free()




