I know that this might be a commonly asked question but i could not find an answer. How can i make an array of textures and make a gameobject cycle through those textures over time. Any help would be nice.
2 Answers
2var textures : Texture2D[];
var delay = 1.0;
private var textureCounter = 0;
function Start () {
InvokeRepeating("CycleTextures", delay, delay);
}
function CycleTextures () {
textureCounter = ++textureCounter % textures.length;
renderer.material.mainTexture = textures[textureCounter];
}
i have attached this script to the gameobject which i wish to change texture but nothing is happening. any ideas why?
Tested it and it works fine. Created empty scene, added a sphere, added a directional light, added script to sphere, set number of textures to 4, filled the texture2d slots with 4 different textures, left delay at 1, hit play, watched the textures change.
– BFDesign
great script, Eric5h5. I must say, your the best coder I "Know"
– zmar0519