GDScript中是否有C#结构/类的等价物?例如。
struct Player
{
string Name;
int Level;
}发布于 2019-05-08 02:44:22
Godot3.1.1 gdscript不支持structs,但可以使用classes、dict或lua style table syntax实现类似的结果
http://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html
GDScript可以包含多个内部类,请使用模仿上面的示例的适当属性创建一个内部类:
class Player:
var Name: String
var Level: int下面是使用Player类完整示例:
extends Node2D
class Player:
var Name: String
var Level: int
func _ready() -> void:
var player = Player.new()
player.Name = "Hello World"
player.Level = 60
print (player.Name, ", ", player.Level)
#prints out: Hello World, 60您还可以使用Lua样式表语法:
extends Node2D
#Example obtained from the official Godot gdscript_basics.html
var d = {
test22 = "value",
some_key = 2,
other_key = [2, 3, 4],
more_key = "Hello"
}
func _ready() -> void:
print (d.test22)
#prints: value
d.test22 = "HelloLuaStyle"
print (d.test22)
#prints: HelloLuaStyle仔细查看官方文档,了解详细信息:

https://stackoverflow.com/questions/56022622
复制相似问题