ButtonHandler.cs 924 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class ButtonHandler : MonoBehaviour
  4. {
  5. /// <summary>
  6. /// React to a button click event. Used in the UI Button action definition.
  7. /// </summary>
  8. /// <param name="button"></param>
  9. public void onButtonClicked(Button button)
  10. {
  11. // which GameObject?
  12. GameObject go = GameObject.Find("GameController");
  13. if (go != null)
  14. {
  15. TestHome gameController = go.GetComponent<TestHome>();
  16. if (gameController == null)
  17. {
  18. Debug.LogError("Missing game controller...");
  19. return;
  20. }
  21. if (button.name == "JoinButton")
  22. {
  23. gameController.onJoinButtonClicked();
  24. }
  25. else if (button.name == "LeaveButton")
  26. {
  27. gameController.onLeaveButtonClicked();
  28. }
  29. }
  30. }
  31. }