DELAY TEXTURE CHANGE
Hi there,
I have the script below which changes the material which works well. I just want to add a delay to it. Assuming it's a Delaycallback event? But not quite 100% on how and what to add to the script. Any help would be great.
Best,
Rich
// -----JS CODE-----
// Use in "Initialize" event
// @input Component.MeshVisual meshVisual
// @input Asset.Material[] materials
// Our starting texture index
var currentItemIndex = 0;
// Function to clear the current materials and add a new one
function setMaterial(material){
script.meshVisual.clearMaterials();
script.meshVisual.addMaterial(material);
}
// Assign the initial material to our meshVisual
setMaterial(script.materials[currentItemIndex]);
// Define what happens when you tap.
function changeMaterial () {
// Increment the current item index
currentItemIndex += 1;
// We need the current item index to wrap around
// once it's higher than the number of items we have.
currentItemIndex = currentItemIndex % script.materials.length;
// Change the mesh's material
setMaterial(script.materials[currentItemIndex]);
}
// Bind the function to the tap event.
var touchEvent = script.createEvent("TapEvent");
touchEvent.bind(changeMaterial);
Are you still searching for the solution or the problem solved?
If you still searching, please let me know and I will explain to you by example
Hi there! Thanks for reaching out :) Yes I am still looking for a solution. Haven't quite nailed it so if you could that would be amazing!
Thanks,
Rich