I wrote a simple count down timer script.But the text dos not show the time in script. My script is below,
public float timeRemaining = 10;
public bool timerIsRunning = false;
public Text timeText;
public GameObject TimeoutUi;
public GameObject Timercanva;
private void Start()
{
// Starts the timer automatically
timerIsRunning = true;
}
void Update()
{
if (timerIsRunning)
{
if (timeRemaining > 0)
{
timeRemaining -= Time.deltaTime;
DisplayTime(timeRemaining);
}
else
{
TimeoutUi.SetActive(true);
Timercanva.SetActive(false);
timeRemaining = 1;
timerIsRunning = false;
}
}
}
void DisplayTime(float timeToDisplay)
{
timeToDisplay += 1;
float minutes = Mathf.FloorToInt(timeToDisplay / 60);
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
timeText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}
no compile errors with that.I set the time in inspector to ten seconds but in game,timer count down from 50 seconds,
I set a function to call when time is over,it works to seconds which I put into script and inspector.New at this Timer guy so please help!Sorry for bad English:)