using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using Multiplayer; public class GameMode : MonoBehaviour { public Recipe recipe; public CharacterMovement charMove; public Timer timer; public GameObject winCanvas; public GameObject loseCanvas; private void OnEnable() { ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameWin,GameWin); ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameOver, GameLose); } private void OnDisable() { ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameWin); ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameOver); } void Update() { //CheckValues(); if (charMove.CheckNearby()) { if (recipe.CheckVictory()) { PreGameWin(); } } } public void EndGame() { Multiplayer.ClientManager.Instance.SendMessage(Multiplayer.PlayerMsgID.Lobby); } public void PreGameWin() { ClientManager.Instance.SendMessage(PlayerMsgID.GameWin); } public void PreGameLose() { ClientManager.Instance.SendMessage(PlayerMsgID.GameOver); } public void GameWin(NetworkMessage msg) { winCanvas.SetActive(true); timer.enabled = false; } public void GameLose(NetworkMessage msg) { loseCanvas.SetActive(true); timer.enabled = false; } /* //Check the values for player to see if it changes the minimum or maximum values of all players void CheckValues() { float maxDistance = 0; foreach(GameObject gamePlayer in Players) { float distance = (transform.position - gamePlayer.transform.position).magnitude; Player playerScript = gamePlayer.GetComponent(); foreach (GameObject dummy in playerScript.dummies) { float newDis = (transform.position - gamePlayer.transform.position).magnitude; if (newDis < distance) { distance = newDis; } } if (distance > maxDistance) { maxDistance = distance; } } if (maxDistance < DistanceToWin) { if (recipe.CheckVictory()) { //Win Game here } } } */ }