Hello. I have got a plane (flat mesh not aircraft) and 10 textures that I want to swap quickly and after all ten start again so I can simulate a waterfall. How can I get all of the textures to cycle one texture every 0.1 of a second and then loop.
in c#
private Texture[] _textureArray = Texture[] { texture1, texture2, texture3, ... etc };
void Awake()
{
StartCoroutine(Cycler());
}
IEnumerator Cycler()
{
int currentTex = 0;
while(true)
{
yield return new WaitForSeconds(0.1f);
currentTex++;
var tex = _textureArray[currentTex % _textureArray.Length];
.. Assign texture here.
}
}
Explaination:
Start a co-rountine that loops for ever, waiting 0.1 seconds before it runs each time. Then using modulo maths, selects the next texture from the array of textures. It doesn’t matter how many textures you use, it’ll always loop correctly.
Assign ‘tex’ to your plane in the normal way.
[Disclaimer: not tested in unity - may not compile :P]