I'm Trying to Make an Animated Texture, But I failed at it...

Hello. I want to make a model(I already make that model, I added it a texture in my modelling program and imported to Unity3D) that changes its texture by time. But, I can’t make it. I’ll show the code. Here it is:

using UnityEngine;
using System.Collections;

public class HeartScript : MonoBehaviour {
	private int rotationSpeed;
	private float coolDown;
	
	public Material[] heart;
	private int index = 0;
	
	private float passedTime;

	// Use this for initialization
	void Start () {
	renderer.material = heart[index];
	passedTime = 0;
	rotationSpeed = 144;
	coolDown = 1;
	}
	
	// Update is called once per frame
	void Update () {
		passedTime += Time.deltaTime;
		transform.Rotate(0, 0, -rotationSpeed * Time.deltaTime);
		if(passedTime == coolDown){
			if(index == 0){
				index++;
				passedTime = 0;
				renderer.material = heart[index];
			}
		}
		if(passedTime == coolDown){
			if(index == 1){
				index--;
				passedTime = 0;
				renderer.material = heart[index];
			}
		}
	}
	
	void OnGUI(){
		GUI.Label(new Rect(20, Screen.height - 20, 250, 25), "Time: " + passedTime);
	}
}

Ignore the rotation and OnGUI codes by the way. I also wanted to give a rotation to the model, and I was successful at it. Also I added a time counter. I mean, time counter works perfectly, so there is no error in time counting. Thanks for the answers.

if (passedTime == coolDown)

Should probably be

if (passedTime >= coolDown)

Oh, true, passedTime can’t always be equal to 1. It worked, thank you so much. :slight_smile: