请求将Godot 3的GDScript脚本适配迁移至Godot 4
Godot 3 转 Godot 4 脚本修改说明
核心修改点
onready语法更新:Godot 4 中将原onready关键字替换为@onready注解- 枚举导出方式调整:导出枚举的语法从
export(ANIMATION_TYPE)改为类型标注式的@export var animation_type: ANIMATION_TYPE - 变量类型显式声明:为变量添加明确的类型标注,符合 Godot 4 的静态类型规范
修改后的 Godot 4 GDScript 代码
extends Path2D enum ANIMATION_TYPE { LOOP, BOUNCE, } @export var animation_type: ANIMATION_TYPE @onready var animationPlayer: AnimationPlayer = $AnimationPlayer func _ready(): match animation_type: ANIMATION_TYPE.LOOP: animationPlayer.play("MoveAlongPathLoop") ANIMATION_TYPE.BOUNCE: animationPlayer.play("MoveAlongPathBounce")
内容的提问来源于stack exchange,提问作者100k7gm
相关产品推荐
相关产品推荐

