Loop through textures every half second

Hey, Ive got to textures referenced in a script, and in that script i also have a gameObject referenced so i can edited the material at runtime. What id like to do is switch between those two textures every half second (thats just an idea, i would probably make it editable), how would I go about this?

You could something like this:

using UnityEngine;
using System.Collections;

public class TextureLoopScript : MonoBehaviour {
	
	public float duration = 0.5f;
	public Texture[] textures;
	
	// Use this for initialization
	void Start () {
		StartCoroutine(DoTextureLoop());
	}
	
	public IEnumerator DoTextureLoop(){
		int i = 0;
		while (true){
			renderer.material.mainTexture = textures*;*
  •  	i = (i+1)%textures.Length;*
    
  •  	yield return new WaitForSeconds(duration);*
    
  •  }*
    
  • }*
    }

I think it can help you

This is a javascript

var waitTime : float = 0.5;
var textures : Texture2D[];
private var i : int = 0;

// Use this for initialization
function Update ()
{
    Invoke("LoopTexture",waitTime);
}

function LoopTexture()
{
    Debug.Log(i);
    renderer.material.mainTexture = textures*;*

if (i < textures.Length-1)

  • i ++;*
    else
  • i = 0;*
    CancelInvoke(“LoopTexture”);
    }