Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?)

Hello,

I can’t seem to wrap the logic around my head between converting a float to an integer. I have looked at all the other Unity answers and still don’t seem to get it.

It’s this code here that I am having problems with.

Score.GetComponent().score += MainCam.GetComponent().Timer;

Score.GetComponent().score - This is an integer.

MainCam.GetComponent().Timer; - This is a float

IEnumerator PointsTotal() 
	
	{
		if (CountingPoints == false) {
			Score.GetComponent<Score> ().score += ballsLeft;
			Score.GetComponent<Score>().score += MainCam.GetComponent<Controls>().Timer;



			//Score.GetComponent<Score> ().score += MainCam.GetComponent<Controls>().
			yield return new WaitForSeconds (ballsLeft);
			CountingPoints = true;
		}
	}


}

The explicit conversion from float to int is

float timer = Time.time;
int score = (int)timer;

so your code could be

Score.GetComponent().score += (int)MainCam.GetComponent().Timer;

I would be worried about using this though because ints cannot have a decimal point while floats like Timer use it. So your code will round Timer to a whole number before adding it to score. You might just want to use a float to store the score and display it as an int instead.