This is what I would do in my game:
Add a pick_up_coin
in the Player scene script, example:
func pick_up_coin():
coin += 1
score += 100
Create a scene for pickups as an Area2D
scene
- Setup
collision_layer
and collision_mask
to detect only the player (optionally but recommended)
Connect body_entered
signal of the Pickup scene:
func _on_body_entered(body):
if not body is Player: return # if you don't setup collision layer and mask
body.pick_up_coin()
For bullets and projectiles you can do the same but with take_damage
in the Player script:
func take_damage(damage):
self.health = max(0, health - damage)
and in the projectile script:
func _on_body_enter(body):
body.take_damage(damage)