所以我使用的是Godot 3 的Mono 版本。我的脚本是用C# 编写的。我正在尝试遵循本教程:http ://docs.godotengine.org/en/latest/getting_started/step_by_step/singletons_autoload.html
但是代码是在 GDScript 中的,我对它的最佳尝试都没有成功。我已经正确编译了脚本(必须将它们添加到我的.csproj
),但我似乎无法访问我在其中设置的 PlayerVarsGlobal.cs
对象TitleScene.cs
Global.cs
使用系统配置为自动加载;使用戈多;
public class Global : Node {
private PlayerVars playerVars;
public override void _Ready () {
this.playerVars = new PlayerVars();
int total = 5;
Godot.GD.Print(what: "total is " + total);
this.playerVars.total = total;
GetNode("/root/").Set("playerVars",this.playerVars);
}
}
PlayerVars.cs
存储变量的类。
public class PlayerVars {
public int total;
}
TitleScene.cs
- 附加到我的默认场景:
using System;
using Godot;
public class TitleScene : Node {
public override void _Ready () {
Node playervars = (Node) GetNode("/root/playerVars");
Godot.GD.Print("total in titlescene is" + playervars.total);
}
}
我觉得我在做一些明显错误的事情。有任何想法吗?