You could try something like this in your sanity script, assuming the player node is always called Player
and it always has a child node called Light2D
:
extends Area2D
func _on_sanity_body_entered(body):
if (body.name == "Player"):
body.get_node("Light2D").texture_scale + = 1
queue_free()
Though, what I would recommend doing is adding a function to your player script and having the sanity object call that. Something like this:
Player script
func perform_sanity_pickup():
get_node("Light2D").texture_scale += 1
print ("Player got some sanity")
Then on the sanity script:
extends Area2D
func _on_sanity_body_entered(body):
if (body.has_method("perform_sanity_pickup"):
body.perform_sanity_pickup()
queue_free()
That way, you can change the layout of the player and just update perform_sanity_pickup
, the player node doesn't have to be called Player
exactly for the pickup to work, and if you later decide to give something else the ability to pickup sanity it only needs to implement perform_sanity_pickup
and it should work.