using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class GameMode : MonoBehaviour {
|
|
|
|
//references to all players
|
|
List<GameObject> Players = new List<GameObject>();
|
|
|
|
public float XDistanceToWin = 10.0f;
|
|
public float ZDistanceToWin = 10.0f;
|
|
|
|
//Min and max values
|
|
float minX = 0;
|
|
float maxX = 0;
|
|
float minZ = 0;
|
|
float maxZ = 0;
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
//Check for win condition
|
|
minX = Players[0].transform.position.x;
|
|
maxX = minX;
|
|
minZ = Players[0].transform.position.z;
|
|
maxZ = minZ;
|
|
|
|
foreach (GameObject player in Players)
|
|
{
|
|
CheckValues(player.transform.position);
|
|
}
|
|
CheckForVictory();
|
|
|
|
}
|
|
|
|
//Check the values for player to see if it changes the minimum or maximum values of all players
|
|
void CheckValues(Vector3 player)
|
|
{
|
|
if (player.x > maxX)
|
|
{
|
|
maxX = player.x;
|
|
}
|
|
else if (player.x < minX)
|
|
{
|
|
minX = player.x;
|
|
}
|
|
|
|
if (player.z > maxZ)
|
|
{
|
|
maxZ = player.z;
|
|
}
|
|
else if (player.z < minZ)
|
|
{
|
|
minZ = player.z;
|
|
}
|
|
}
|
|
|
|
//Check to see if the players win
|
|
void CheckForVictory()
|
|
{
|
|
if ((maxX - minX) < XDistanceToWin)
|
|
{
|
|
if ((maxZ - minZ) < ZDistanceToWin)
|
|
{
|
|
//Game Win goes here
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public List<GameObject> GetPlayers()
|
|
{
|
|
return Players;
|
|
}
|
|
}
|