Fixed GetNode inconsistencies (#5056)

* Fixed GetNode inconsistencies (C#)

The generic method should be used instead. See #4794.
This commit is contained in:
BlueStag
2021-07-01 07:06:13 +01:00
committed by GitHub
parent 3f4e1f3a95
commit a090a578fb
3 changed files with 5 additions and 5 deletions

View File

@@ -261,7 +261,7 @@ To obtain it using a camera, the following code can be used:
{
if (@event is InputEventMouseButton eventMouseButton && eventMouseButton.Pressed && eventMouseButton.ButtonIndex == 1)
{
var camera = (Camera)GetNode("Camera");
var camera = GetNode<Camera>("Camera");
var from = camera.ProjectRayOrigin(eventMouseButton.Position);
var to = from + camera.ProjectRayNormal(eventMouseButton.Position) * RayLength;
}

View File

@@ -83,7 +83,7 @@ There are two ways to load resources from code. First, you can use the ``load()`
public override void _Ready()
{
var texture = (Texture)GD.Load("res://robi.png"); // Godot loads the Resource when it reads the line.
var sprite = (Sprite)GetNode("sprite");
var sprite = GetNode<Sprite>("sprite");
sprite.Texture = texture;
}

View File

@@ -76,7 +76,7 @@ This means that any node can access a singleton named "PlayerVariables" with:
.. code-tab:: csharp
var playerVariables = (PlayerVariables)GetNode("/root/PlayerVariables");
var playerVariables = GetNode<PlayerVariables>("/root/PlayerVariables");
playerVariables.Health -= 10; // Instance field.
If the **Enable** column is checked (which is the default), then the singleton can
@@ -254,7 +254,7 @@ Finally, we need to fill the empty callback functions in the two scenes:
public void OnButtonPressed()
{
var global = (Global)GetNode("/root/Global");
var global = GetNode<Global>("/root/Global");
global.GotoScene("res://Scene2.tscn");
}
@@ -274,7 +274,7 @@ and
public void OnButtonPressed()
{
var global = (Global)GetNode("/root/Global");
var global = GetNode<Global>("/root/Global");
global.GotoScene("res://Scene1.tscn");
}