i am trying to display the countDown on the game screen and have successFully done it but its being displayed in miliseconds i just want to display in minutes and seconds left like 1:23 1:22 1:21 and so on.
i have written a script for this and i am attaching it here.
using UnityEngine;
using System.Collections;
public class TimerScript : MonoBehaviour {
private float timeLeft = 300;
float startTime ;
public GameController _gamecontroller;
// Use this for initialization
void Start () {
startTime = 0;
guiText.material.color = Color.black;
_gamecontroller = GameObject.FindObjectOfType(typeof(GameController)) as GameController;
}
void Update () {
Countdown();
}
void Countdown() {
timeLeft = startTime - Time.time;
ShowTime();
if(timeLeft <0){
timeLeft = 0;
}
}
void ShowTime() {
int minutes;
int seconds;
string timeString;
minutes = timeLeft / 60;
seconds = timeLeft % 60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
right now i am getting an error at the line in showtime() method in the line
minutes = timeLeft / 60;
seconds = timeLeft % 60;
""can not implicitly convert float to int.an explicit conversion exists(are you missing a cast)?
any please help me sorting it out.