Eyaan I see the brackeys tutorial is taking victims.
if the player is some global thing, manage it's demise through an autoload.
it's a bit advanced, but:
in the autoload, let's call it player_manager
, create a signal, call it something like kill_player
signal kill_player
in player ready(), connect the signal to a function that kills the player. you have one called killed_()
, let's use that:
func _ready():
PlayerManager.kill_player.connect(killed_)
when your area triggers, call the signal in the autoload:
func _on_body_entered(body)
PlayerManager.kill_player.emit()
autoloads are unique and run outside the scene. when the game starts, it creates nodes with the autoload scripts. you can access autoloads from anywhere, as they are given a unique name (the name of the file, capitalized and without spaces)
player_manager
becomes PlayerManager
if the player is the one colliding with the coin and dead area, you don't need anything special, the function has a body
parameter and that is going to be the player:
func _on_body_entered(body):
body.killed_()
body is the player. you can change the names of these variables
func _on_body_entered(player):
player.killed_()
if something other than the player can collide with this thing, you have to check for method first or do some other test:
func _on_body_entered(player):
if player.has_method("killed_"):
player.killed_()