Now that our event is firing every time the player jumps, we need a way to capture that action:
- Go back to GameBehavior and update the following code:
public class GameBehavior : MonoBehaviour, IManager...
{
// ... No changes needed ...
void Start()
{
// ... No changes needed ...
}
public void Initialize()
{
_state = "Manager initialized..";
_state.FancyDebug();
debug(_state);
LogWithDelegate(debug);
// 1
GameObject player = GameObject.Find("Player");
// 2
PlayerBehavior playerBehavior =
player.GetComponent<PlayerBehavior>();
// 3
playerBehavior.playerJump += HandlePlayerJump;
}
// 4
public void HandlePlayerJump()
{
debug("Player has jumped...");
}
// ... No changes in Print,
LogWithDelegate, or
OnGUI ...
}