尝试使用 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
升级到 Godot 4 后,没有“@”的“onready”似乎对我来说中断了。
关于Godot Onready var 不起作用并在类主体中出现错误 Unexpected "Identifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75439334/