- Home /
Question by
Factory5162 · Feb 08 at 02:53 AM ·
textures
animating texture through script
I am trying to change the texture of a plane with 200 image textures. My issue is that if i put a speed value the image will start jittering for some reason. It works well with speed 0 only.
IEnumerator AnimateVision()
{
for (int i = 0; i < BaseMap.Length; i++)
{
m_Renderer.material.SetTexture ("_BaseMap",BaseMap[i]);
m_Renderer.material.SetTexture ("_EmissionMap", BaseMap[i]);
yield return new WaitForSeconds(Speed);
if (i == BaseMap.Length - 1 )
{
i = 0;
}
}
}
Comment
Best Answer
Answer by Factory5162 · Feb 08 at 05:08 AM
I was able to solve it without for loop like this and the texture animation is looping now :)...
IEnumerator Animation()
{
int i = 0;
float time = 0;
while (i < BaseMap.Length)
{
m_Renderer.material.SetTexture("_BaseMap", BaseMap[i]);
m_Renderer.material.SetTexture("_EmissionMap", BaseMap[i]);
time += Time.deltaTime / Speed;
if (time >= Speed)
{
i = i + 1;
time = 0;
if (i == BaseMap.Length - 1)
{
i = 0;
}
}
yield return null;
}
}
Your answer
