英文:
Godot Onready var not working and getting error Unexpected "Identifier" in class body
问题
尝试使用onready
变量来启动射线检测以播放NPC动画,但即使射线工作,动画也不会播放。
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 # 用实际的函数内容替换此行。
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")
解释/替代简单解决方案以修复代码,适用于初学者/中级水平的解释。
英文:
trying to use onready var to start a raycast to play a animation for a npc but even though the ray works it wont play the animation
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")
Explanation/Alternative simple answer on how to fix the code in a beginner/intermediate level explanationyour text
答案1
得分: 1
我通过在 onready
前面加上一个 "@ " 来解决了这个问题。
@onready var raycast = $RayCast3D
在升级到 Godot 4 后,没有 "@ " 的 "onready" 似乎对我不起作用。
英文:
I fixed this issue by putting a "@" in front of onready
.
@onready var raycast = $RayCast3D
"onready" without the "@" seemed to break for me after upgrading to Godot 4.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论