mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
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:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user