Browse Source

Game mode logic added

master
MB 5 years ago
parent
commit
7733d1c869
2 changed files with 95 additions and 0 deletions
  1. +84
    -0
      Assets/Scipts/GameMode.cs
  2. +11
    -0
      Assets/Scipts/GameMode.cs.meta

+ 84
- 0
Assets/Scipts/GameMode.cs View File

@ -0,0 +1,84 @@
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;
//Time stuff
public float MaxTimer = 120.0f;
float Timer = 0.0f;
void Start()
{
Timer = MaxTimer;
}
void Update()
{
//Handle timer
Timer -= 1.0f * Time.deltaTime;
if (Timer <= 0.0f)
{
//Game Lose code here
}
//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
}
}
}
}

+ 11
- 0
Assets/Scipts/GameMode.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 553b7b4f739e7334b9e1055b3688e5e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save