Question by
gss214 · Sep 06, 2015 at 12:54 AM ·
timescalerealtimepause menuunpause
I want a countdown when unpause the game
tried realtimeSinceStartup but I can not put him start so unpause
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Pause : MonoBehaviour
{
public static bool paused = false;
public GameObject menu;
public bool isShowing;
public Button b1;
public Button b2;
public Button b3;
//
public float tempo = 4;
public float tempoPause;
public bool inicioTempoPause;
public float StartTimer;
public float StartTimerValue;
public Text contador;
public GameObject contadorObj;
public bool isUnPaused;
void Start () {
isShowing = false;
paused = false;
contadorObj.SetActive (false);
isUnPaused = false;
}
void Update()
{
if (isShowing == true) {
menu.SetActive (true);
}
if (isShowing == false) {
menu.SetActive (false);
}
int tempoTexto = (int)tempo;
if (isUnPaused == true) {
if (tempo > 0) {
contadorObj.SetActive (true);
tempo -= Time.deltaTime;
contador.text = " " + tempoTexto;
}
if (tempo < 1) {
contador.text = "Go!";
}
if (tempo == -1) {
contadorObj.SetActive (false);
}
}
//dont work ):
StartTimer = Time.realtimeSinceStartup;
if (inicioTempoPause == true) {
tempoPause = Time.realtimeSinceStartup - StartTimer;
}
}
public void pausedFunction () {
paused = !paused;
if (paused == true) {
Time.timeScale = 0;
isShowing = true;
PlayerControl.speed = 0;
}
if (paused == false) {
Time.timeScale = 0;
isShowing = false;
PlayerControl.speed = 0.05f;
inicioTempoPause = true;
}
}
}
Comment
Your answer