Skip to content

Instantly share code, notes, and snippets.

@surayashivji
Created April 26, 2017 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surayashivji/dbe1a9094d3e95b1e99fa84a47bfa072 to your computer and use it in GitHub Desktop.
Save surayashivji/dbe1a9094d3e95b1e99fa84a47bfa072 to your computer and use it in GitHub Desktop.
Timer is a countdown
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
private Text timerText;
private float myTimer = 30.0f;
// public float MyTimer
// {
// get { return myTimer; }
// }
private bool isGMPaused;
private ScoreManager scoreManager;
// Use this for initialization
void Start ()
{
timerText = GetComponent<Text> ();
scoreManager = GameObject.Find("ScoreManager").GetComponent<ScoreManager>();
isGMPaused = GameManager.Instance.isPaused;
}
// Update is called once per frame
void Update ()
{
if (!isGMPaused) {
myTimer -= Time.deltaTime;
}
timerText.text = myTimer.ToString();
if (myTimer < 1) {
Debug.Log (myTimer);
Debug.Log ("We out here");
// ScoreManager.Instance.SaveGameState (true);
PrepareForNextLevel(true);
// SceneManager.LoadScene("WinLevel");
}
}
#region SCORE_MANAGER_ACCESSORS
public void AddToScore(int val)
{
scoreManager.UpdateScore (val);
}
public void PrepareForNextLevel(bool didWin)
{
scoreManager.SaveGameState (didWin);
}
#endregion // SCORE_MANAGER_ACCESSORS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment