Commit 00619417 authored by Ashley's avatar Ashley

Timer is done

parent 1fc5c3e0
......@@ -26,7 +26,7 @@ public class Dash : AbstractBehavior {
}
void Start() {
dashMeter = GameObject.FindGameObjectWithTag("DashMeter").transform;
//dashMeter = GameObject.FindGameObjectWithTag("DashMeter").transform;
}
// Should be called every frame
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class GameManager : SingletonBehaviour<GameManager>
......@@ -8,10 +9,12 @@ public class GameManager : SingletonBehaviour<GameManager>
private bool _isPaused;
private float _levelTimer;
public Text timerText;
void Awake()
{
DontDestroyOnLoad(this);
isPaused = true;
}
public bool isPaused
......@@ -22,19 +25,19 @@ public class GameManager : SingletonBehaviour<GameManager>
}
set
{
_isPaused = value;
if (isPaused)
{
//set timescale back to normal
isPaused = false;
Time.timeScale = 1;
Debug.Log("Game is unpaused");
}
else
{
//set timescale to zero
isPaused = true;
Time.timeScale = 0;
Debug.Log("Game is paused");
}
_isPaused = value;
}
}
......@@ -56,4 +59,18 @@ public class GameManager : SingletonBehaviour<GameManager>
Debug.Log("Changing level state");
levelTimer = Time.time;
}
//formats the time for the text object
private string formatTime(float time)
{
int minutes = Mathf.FloorToInt(time / 60F);
int seconds = Mathf.FloorToInt(time - minutes * 60);
return string.Format("{0:0}:{1:00}", minutes, seconds);
}
//updates the text object
void Update()
{
string currentTime = formatTime(Time.time - levelTimer);
timerText.text = "Time: " + currentTime;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment