You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求将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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:09:52