mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-08 10:10:54 +03:00
Fixed GetNode inconsistencies (#5056)
* Fixed GetNode inconsistencies (C#) The generic method should be used instead. See #4794.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user