You are on page 1of 2

using UnityEngine;

using UnityEngine.UI;
using System.Collections;
public class GameManager : MonoBehaviour {
public
public
public
public
public
public
public
public

Camera cam;
GameObject[] randomObject;
float timeLeft;
Text Timertext;
GameObject gameOverText;
GameObject restartButton;
GameObject splashScreen;
GameObject startButton;

private float maxWidth;


private bool playing;
public GUIText scoreText;
public int score;
public Vector3[]positions;
// Use this for initialization
void Start () {
if (cam == null){
cam = Camera.main;
}
playing = false;
int randomNumber = Random.Range (0, positions.Length);
transform.position = positions [randomNumber];
score = 0;
UpdateScore() ;
}
void FixedUpdate () {
if (playing){
timeLeft -= Time.deltaTime;
if (timeLeft < 0) {
timeLeft = 0;
}
}
}
public void StartGame () {
splashScreen.SetActive (false);
startButton.SetActive (false);
StartCoroutine (Spawn ());
}
IEnumerator restart(){
yield return new WaitForSeconds (2.0f);
playing = true;
while (timeLeft> 0){
yield return new WaitForSeconds (Random.Range (1.0f, 2.0
f));
}

yield return new WaitForSeconds (2.0f);


gameOverText.SetActive (true);
yield return new WaitForSeconds (2.0f);
restartButton.SetActive (true);
}
public void AddScore (int newScoreValue)
{
score += newScoreValue;
UpdateScore ();
}
void UpdateScore ()
{
scoreText.text = "Score: " + score;
}
}

You might also like