Problem with Displaying the countdown Timer

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.

You need to get your type casting basics right, here.

timeLeft is a float, minutes is an int. In programming, when you assign X to Y, X has to be of type Y, in other words, there always must be a type match. Now let’s look at your statement:

minutes = timeLeft / 60;

You’re assigning the result of the division timeLeft / 60 to minutes which is an int. Now let’s see if that assignment is valid or not:

timeLeft is a float, 60 is an int and we know that float / int will return us a float - This is a rule, the stronger type will always win, so:

int   / int    = int
float / int    = float
int   / float  = float
float / float  = float
float / double = double
... etc

(this holds true for all other math operators, not just division)

So your problem is a type mis-match! What you can do, is to cast the result to force it to become something of a weaker strength, when you cast something, you are forcing it to be something else ONLY in that moment, not always:

 minutes = (int)(timeLeft / 60); // This means, IN THIS MOMENT, I want the result of the division to be of type int

Now everything works.

But please note that when you cast a float/double to an int, what’s after the decimal point will get truncated, so whenever you cast, make sure you don’t lose anything you might need. ex int(5.745) = 5

For your timer purposes, you might wanna check out the Timer class, here’s an example.