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

  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 float XDistanceToWin = 10.0f;
  8. public float ZDistanceToWin = 10.0f;
  9. //Min and max values
  10. float minX = 0;
  11. float maxX = 0;
  12. float minZ = 0;
  13. float maxZ = 0;
  14. void Update()
  15. {
  16. //Check for win condition
  17. minX = Players[0].transform.position.x;
  18. maxX = minX;
  19. minZ = Players[0].transform.position.z;
  20. maxZ = minZ;
  21. foreach (GameObject player in Players)
  22. {
  23. CheckValues(player.transform.position);
  24. }
  25. CheckForVictory();
  26. }
  27. //Check the values for player to see if it changes the minimum or maximum values of all players
  28. void CheckValues(Vector3 player)
  29. {
  30. if (player.x > maxX)
  31. {
  32. maxX = player.x;
  33. }
  34. else if (player.x < minX)
  35. {
  36. minX = player.x;
  37. }
  38. if (player.z > maxZ)
  39. {
  40. maxZ = player.z;
  41. }
  42. else if (player.z < minZ)
  43. {
  44. minZ = player.z;
  45. }
  46. }
  47. //Check to see if the players win
  48. void CheckForVictory()
  49. {
  50. if ((maxX - minX) < XDistanceToWin)
  51. {
  52. if ((maxZ - minZ) < ZDistanceToWin)
  53. {
  54. //Game Win goes here
  55. }
  56. }
  57. }
  58. }