Based on your scene tree, the Button
and Label
are siblings with a common parent (the Node2D
), right? And, the script you show is attached to the Button
?
In that case, your $Label
references in the script won't work (and should be generating errors when you run the game).
A references of $Label
will cause the engine to search for a control with that name as a child of the node containing the script (so, as a child of Button
). In this case, that node won't be found.
To find a sibling node, you need to reference it differently. This should work:
extends Button
var cenoura = 0
onready var label = get_node("../Label")
func _ready():
label.text = "BATATA"
func _process(delta):
if cenoura == 1:
label.text = "CENOURA"
func _on_Button_pressed():
cenoura = 1