Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Godotfan |
Hello!
I’m a beginner for both Godot and C# and I’m following the tutorial of documentation and got some questions.
Here is the codes form tutorial.
using Godot;
// IMPORTANT: the name of the class MUST match the filename exactly.
// this is case sensitive!
public class sayhello : Panel
{
public override void _Ready()
{
GetNode("Button").Connect("pressed", this, nameof(_OnButtonPressed));
}
public void _OnButtonPressed()
{
var label = (Label)GetNode("Label");
label.Text = "HELLO!";
}
}
Why the #1 which in the tutorial, it cannot simply work as #2 or #3. Also what’s (Lable)
in the var label = (Label)GetNode("Label");
means here?
#1
var label = (Label)GetNode("Label");
label.Text = "HELLO!";
#2
GetNode("Label").Text = "HELLO!";
#3
var label = GetNode("Label");
label.Text = "HELLO!";
Thanks a lot!