- Home /
Loop Animation of Textures
Hi, Im trying to loop through a list of textures and make an animation based on that.
But after the first "delay" the textures start to flikker.
I have tried to do some debugging, and it seems it just put the images ontop of eachother or reapeating them really fast without the delay.
Any ideas ?
public static List ContentList
public IEnumerator ChangeTextures(Renderer renderer, List<Texture> textures, float delay,bool Play )
{
int i = 0;
while (Play)
{
renderer.material.mainTexture = textures[i];
i = (i+1)%textures.Count;
yield return new WaitForSeconds(delay);
}
}
private void StartContent()
{
//Other stuff
StartCoroutine(ChangeTextures(this.gameObject.renderer, ContentList, 5f,PlayContent));
}
public void Play()
{
StartContent();
EnablePause = false;
PlayContent = true;
this.gameObject.renderer.enabled = true;
}
I don't see anything here that would cause your images to flicker. Try this script from the Unity Wiki. It is doing essentially the same thing, but you can see if it flickers or not for you:
Answer by rodripf · May 14, 2014 at 02:33 PM
I think the problem here is that you are changing the frames of the animation inside a corutine, which is not in sync with the Unity's frames update. You should change the frames of the animation inside an Update function.
After some test, you where right :)
It was not in sync :D
I used this solution in the end
void Update()
{
if(PlayContent)
{
var index = (int)Time.time * 10;
index = index % ContentList.Count;
renderer.material.mainTexture = ContentList[index];
}
}
Your answer
Follow this Question
Related Questions
Material Not Reverting Back 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Animated Texture Offset 1 Answer
Texture not moving correctly 0 Answers