Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created June 6, 2019 19:51
Show Gist options
  • Save pr00thmatic/5dd54c9038a2966987d3347242295839 to your computer and use it in GitHub Desktop.
Save pr00thmatic/5dd54c9038a2966987d3347242295839 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BallVictoryTriggerer : MonoBehaviour {
void OnEnable () {
}
void OnDisable () {
GameManager.OnGameEndingTriggered -= Asdf;
}
void Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
GameManager.OnGameEndingTriggered += Asdf;
print("bola avisándole a game manager");
GameManager.TriggerVictory();
}
}
public void Asdf (GameMode mode) {
print(mode + "!!!!!!");
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
public static GameManager instance;
public static event Action<GameMode> OnGameEndingTriggered;
void Awake () {
if (instance != null && instance != this) {
Destroy(this);
return;
}
}
public static void TriggerVictory () {
if (OnGameEndingTriggered != null) {
print("game manager disparando el evento");
OnGameEndingTriggered(GameMode.Victory);
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class UIManager : MonoBehaviour {
void OnEnable () {
GameManager.OnGameEndingTriggered += Avisar;
}
void OnDisable () {
GameManager.OnGameEndingTriggered -= Avisar;
}
public void Avisar (GameMode gameMode) {
print(gameMode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment