You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using Multiplayer;
  6. public class GameMode : MonoBehaviour {
  7. public Recipe recipe;
  8. public CharacterMovement charMove;
  9. public Timer timer;
  10. public GameObject winCanvas;
  11. public GameObject loseCanvas;
  12. private void OnEnable()
  13. {
  14. ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameWin,GameWin);
  15. ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameOver, GameLose);
  16. }
  17. private void OnDisable()
  18. {
  19. ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameWin);
  20. ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameOver);
  21. }
  22. void Update()
  23. {
  24. //CheckValues();
  25. if (charMove.CheckNearby())
  26. {
  27. if (recipe.CheckVictory())
  28. {
  29. PreGameWin();
  30. }
  31. }
  32. }
  33. public void EndGame()
  34. {
  35. Multiplayer.ClientManager.Instance.SendMessage(Multiplayer.PlayerMsgID.Lobby);
  36. }
  37. public void PreGameWin()
  38. {
  39. ClientManager.Instance.SendMessage(PlayerMsgID.GameWin);
  40. }
  41. public void PreGameLose()
  42. {
  43. ClientManager.Instance.SendMessage(PlayerMsgID.GameOver);
  44. }
  45. public void GameWin(NetworkMessage msg)
  46. {
  47. winCanvas.SetActive(true);
  48. timer.enabled = false;
  49. }
  50. public void GameLose(NetworkMessage msg)
  51. {
  52. loseCanvas.SetActive(true);
  53. timer.enabled = false;
  54. }
  55. }