无法从 Godot 中的另一个脚本访问变量
unable to right to a variable from another script in Godot
正在尝试在此脚本中访问变量重力
extends KinematicBody2D
class_name Actor
export var speed: = Vector2(300.0, 1000.0)
export var gravity = 3000.0
var velocity: = Vector2.ZERO
func _physics_process(delta: float) -> void:
velocity.y += gravity*delta
#velocity.y = max(velocity.y, speed.y)
velocity = move_and_slide(velocity)
来自这个脚本
extends Actor
func _physics_process(delta: float) -> void:
var direction = Vector2(
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),0.0
)
velocity =
我收到错误意外令牌:Identifier:velocity
我使用 class_name 不正确吗?
您可以从基 class 访问 velocity
和 gravity
变量,但您需要在一个函数内进行,例如:
extends Actor
func _physics_process(delta: float) -> void:
velocity += Vector2.ZERO # just an example
正在尝试在此脚本中访问变量重力
extends KinematicBody2D
class_name Actor
export var speed: = Vector2(300.0, 1000.0)
export var gravity = 3000.0
var velocity: = Vector2.ZERO
func _physics_process(delta: float) -> void:
velocity.y += gravity*delta
#velocity.y = max(velocity.y, speed.y)
velocity = move_and_slide(velocity)
来自这个脚本
extends Actor
func _physics_process(delta: float) -> void:
var direction = Vector2(
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),0.0
)
velocity =
我收到错误意外令牌:Identifier:velocity
我使用 class_name 不正确吗?
您可以从基 class 访问 velocity
和 gravity
变量,但您需要在一个函数内进行,例如:
extends Actor
func _physics_process(delta: float) -> void:
velocity += Vector2.ZERO # just an example