0

我在游戏中添加了声音,但是在我玩了几下游戏后,它会关闭并说(尝试在空实例上的基本“空实例”中调用函数“播放”),然后我去堆栈交换,他们说我的前两个函数的缩进有问题,来这里寻求缩进帮助。

我尝试缩进前两个,但它仍然不起作用,我会收到更多错误说“意外缩进”或解析器错误:Unndent 与任何其他缩进级别不匹配。

func _ready():
    position = get_viewport_rect().size / 2
    direction.x = rand_range(-1, 1)
    direction.y = rand_range(-1, 1)
    direction = direction.normalized()
    width = get_viewport_rect().size.x
    height = get_viewport_rect().size.y

func _process(delta):
    position += direction * speed * delta
    if position.x < 0 or position.x > width:
        direction.x = -direction.x
    if position.y < 0 or position.y > height:
        direction.y = -direction.y

func _on_UFO_input_event( viewport, event, shape_idx ):
    if lose:
     return 
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
        direction.x = rand_range(-1, 1)
        direction.y = rand_range(-1, 1)  
        direction = direction.normalized()
        position.x = rand_range(1, width -1)
        position.y = rand_range(1, height -1)
        speed += 5      
        hit = true
        $HitSound.play()

我希望我的游戏声音可以播放,但点击几下后它会关闭并显示(尝试在空实例上的基本“空实例”中调用函数“播放”)

4

0 回答 0