I added sound to my game, but after I played my game for a few clicks it would close and say (Attempt to call function'play' in base 'null instance' on a null instance) and I went to stack exchange and they said there was something wrong with my indentation on my first two functions and to come here for indentation help.
I tried indenting the first two, but it still wouldn't work and i would get more errors saying 'Unexpected Indent' or Parser Error: Unindent does not match any other indentation level.
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()
I expected the sound of my game to play but after a few clicks it shuts down and says (Attempt to call function'play' in base 'null instance' on a null instance)