我在游戏中添加了声音,但在我几次点击游戏后,它会关闭并说(试图在空实例的基本“空实例”中调用函数“ play”),然后我去了堆栈交换他们说我的前两个功能的缩进有问题,请到这里寻求缩进帮助。
我尝试缩进前两个缩进,但仍然无法正常工作,并且会收到更多错误,提示“意外缩进”或解析器错误:缩进与任何其他缩进级别都不匹配。
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()
我希望可以播放游戏的声音,但是单击几次后它会关闭并说(尝试在空实例的基本“空实例”中调用函数“ play”)