Godot Onready var 不起作用并在类主体中出现错误 Unexpected "Identifier"

标签 godot onready

尝试使用 onready var 启动光线转换来为 npc 播放动画,但即使光线有效,它也不会播放动画

code:

extends Node3D

enum
{
Attack1,
Death1,
Idle,
Pose,
Walk
}

var state = Idle

onready var raycast = $RayCast3D
onready var ap = $"maxdamage_zombie-low-poly"
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

if raycast.is_colliding():
    state = Attack1
else:
    state = Idle

match state:
    Attack1:
        ap.play("Attack1")
    Death1:
        ap.play("Death1")
    Idle:
        ap.play("Idle")
    Pose:
        ap.play("Pose")
    Walk:
        ap.play("Walk")

关于如何修复初学者/中级水平解释中的代码的解释/替代简单答案您的文本

最佳答案

我通过在 onready 前面添加“@”解决了这个问题。

@onready var raycast = $RayCast3D

https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#onready-annotation

升级到 Godot 4 后,没有“@”的“onready”似乎对我来说中断了。

关于Godot Onready var 不起作用并在类主体中出现错误 Unexpected "Identifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75439334/

相关文章:

game-development - Godot 信号是否充当事件处理程序?

glsl - 如何获得 godot 空间着色器的分辨率?

godot 如何知道点击是否在 Sprite 内部 :

javascript - 添加到我的代码中

javascript - 在javascript中,当第一个函数准备好时执行一个函数

2d - Godot:如何实现二维固定关节?

godot - 有没有办法在 Godot 中创建真正的自定义类型?

主要提供 document/onready 功能的 Javascript 框架

javascript - setInterval多次触发函数