Improve C# GD.Load() examples

* Use typed version of GD.Load()
* Use absolute paths (i.e., prefixed with "res://")
* Use "Path/To/" intermediate path values on abstract examples, to
  illustrate that files can live in various directories
* Use PascalCase on files that are not GDScript or GLSL
This commit is contained in:
Mark Wilson
2023-10-06 13:29:26 -04:00
parent fd94ebfaab
commit 147d2233c7
8 changed files with 38 additions and 29 deletions

View File

@@ -87,7 +87,8 @@ 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.
// Godot loads the Resource when it executes this line.
var texture = GD.Load<Texture>("res://Robi.png");
var sprite = GetNode<Sprite2D>("sprite");
sprite.Texture = texture;
}
@@ -128,7 +129,7 @@ To get an instance of the scene, you have to use the
.. code-tab:: csharp
private PackedScene _bulletScene = (PackedScene)GD.Load("res://bullet.tscn");
private PackedScene _bulletScene = GD.Load<PackedScene>("res://Bullet.tscn");
private void OnShoot()
{