【问题标题】:unable to right to a variable from another script in Godot无法从 Godot 中的另一个脚本中获取变量的权限
【发布时间】:2020-05-18 04:26:59
【问题描述】:

试图在这个脚本中访问可变重力

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 = 

我收到错误 Unexpected token: Identifier:velocity

我是否错误地使用了 class_name?

【问题讨论】:

    标签: godot gdscript


    【解决方案1】:

    您可以从基类访问velocitygravity 变量,但您需要在函数中进行,例如:

    extends Actor
    
    func _physics_process(delta: float) -> void:
        velocity += Vector2.ZERO #  just an example
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-02
      • 1970-01-01
      • 2022-07-16
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多