Scene Manager

Add a SceneManager script to a Godot that communicates between the components of a scene.

1. Setting up the Godot Project

2. Create SceneManager.gd script

4. Update the PlayerController

5. Log the player signal

6. Add an Item

7. Add another example Area

8. Documentation

Full SceneManager.gd script

extends Node2D

# communicate between scene components

export (NodePath) var player_path
onready var player = get_node(player_path)

func _on_player_hit():
	print('player hit!', Global.player_lives)
	if Global.player_lives > 1:
		Global.player_lives -= 1
	else:
		print('game over!')
		player.dies()


func _on_item_collected():
	Global.item_count += 1
	print("you have ", Global.item_count, " items")

Added to PlayerController

# member variables
signal player_hit

func _on_Enemy_body_entered(body):
	emit_signal("player_hit")

func dies():
	is_alive = false
	$AnimatedSprite.play('Dies')

ItemManager.gd

extends Area2D

signal item_collected


func _on_Item_body_entered(body):
	emit_signal("item_collected")