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.

61 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GameMode : MonoBehaviour {
  5. //references to all players
  6. List<GameObject> Players = new List<GameObject>();
  7. public Recipe recipe;
  8. GameObject LocalPlayer;
  9. public float DistanceToWin;
  10. private void Start()
  11. {
  12. LocalPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer;
  13. Players.Add(LocalPlayer);
  14. foreach (GameObject curPlayer in Multiplayer.PlayersManager.Instance.RemotePlayers.Values)
  15. {
  16. Players.Add(curPlayer);
  17. }
  18. }
  19. void Update()
  20. {
  21. CheckValues();
  22. }
  23. //Check the values for player to see if it changes the minimum or maximum values of all players
  24. void CheckValues()
  25. {
  26. float maxDistance = 0;
  27. foreach(GameObject gamePlayer in Players)
  28. {
  29. float distance = (transform.position - gamePlayer.transform.position).magnitude;
  30. Player playerScript = gamePlayer.GetComponent<Player>();
  31. foreach (GameObject dummy in playerScript.dummies)
  32. {
  33. float newDis = (transform.position - gamePlayer.transform.position).magnitude;
  34. if (newDis < distance)
  35. {
  36. distance = newDis;
  37. }
  38. }
  39. if (distance > maxDistance)
  40. {
  41. maxDistance = distance;
  42. }
  43. }
  44. if (maxDistance < DistanceToWin)
  45. {
  46. if (recipe.CheckVictory())
  47. {
  48. //Win Game here
  49. }
  50. }
  51. }
  52. }