Godot Engine Game Development Projects
上QQ阅读APP看书,第一时间看更新

Checking for remaining coins

The main script needs to detect whether the player has picked up all of the coins. Since the coins are all children of CoinCointainer, you can use get_child_count() on this node to find out how many coins remain. Put this in the _process() function so that it will be checked every frame:

func _process(delta):
if playing and $CoinContainer.get_child_count() == 0:
level += 1
time_left += 5
spawn_coins()

If no more coins remain, then the player advances to the next level.