My change color code is obsolete?

So, I’ve been messing around with Unity for about a month and I found a tutorial that taught me how to make a game object change colors. The only problem is that I’m getting these compiler errors that tell me that the code is obsolete. Any tips guys? Also, here’s the code:

void Update ()
{
	changetime += Time.deltaTime;

	if (changetime == 1){
		Sphere.renderer.material.color = Color.red;
	}
	if (changetime == 2){
		Sphere.renderer.material.color = Color.green;
	}
	if (changetime == 3){
		Sphere.renderer.material.color = Color.blue;
	}

First of all, I assume “Sphere” is the problem. If I remember correctly, that’s an obsolete way of calling a Sphere class? (Was it back in Unity 3?) Either way, you shouldn’t capitalize “Sphere.”

Assuming this script is attached to the sphere you want to change the color for. You can directly access its renderer components using this:

gameObject.renderer.material.color = Color.red;

Second, there is no chance your “changetime” variable will be perfectly equal to 1, 2, or 3 by using “Time.deltaTime” as increments. Time.deltaTime is the time difference between this and last frame, which when added all together in however many you ways possible, it’s almost never going to be a perfect integer.

Try making a range for the “changetime” variable.

if (changetime > 1 && changetime < 2){
    gameObject.renderer.material.color = Color.red;
}

Now the color of the sphere will be red when the time is greater than 1 second but less than 2.