Hi! My script work time but getkey “G” to reload time “Restart” is doesn’t work, You can check my script what’s wrong? Thanks!
private var startTime;
private var restartime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
function Awake() {
startTime = Time.time * restartime;
}
function OnGUI () {
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
if (restSeconds == 60) {
print ("One Minute Left");
}
if (restSeconds == 1790) {
}
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (125,Screen.height - 75,135,20), text);
}
function Fixed() {
if (Input.GetKeyDown("g")) {
restartime = 1800;
}
}
Why don’t you just do it with something like this :
#pragma strict
var theTimer : float = 0.0;
var theStartTime : float = 120.0;
function Start()
{
theTimer = theStartTime;
}
function Update()
{
theTimer -= Time.deltaTime;
if ( parseInt(theTimer) == 60)
{
Debug.Log("One Minute Left");
}
if (theTimer <= 0)
{
Debug.Log("OUT OF TIME");
theTimer = 0;
}
if ( Input.GetKeyUp(KeyCode.G) )
{
theTimer = theStartTime;
}
}
function OnGUI()
{
var text : String = String.Format ( "{0:00}:{1:00}", parseInt( theTimer / 60.0 ), parseInt( theTimer % 60.0 ) );
GUI.Label( Rect( 125, Screen.height - 75, 135, 20), text );
}
Again doesn’t work
private var startTime;
private var restartime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
function OnGUI () {
var guiTime = Time.time - startTime;
Debug.Log(startTime + "Resetting"+Time.time);
restSeconds = countDownSeconds - (guiTime);
if (restSeconds == 60) {
...
}
if (restSeconds == 1790) {
...
}
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (125,Screen.height - 75,135,20), text);
}
function Update() {
if (Input.GetKeyDown("g")) {
restartime = 1800;
Debug.Log("Resetting");
}
}