- Home /
Add a delay when randomizing a material
Hey guys, I am trying to make a dance floor that flashes red, blue, and green. Right now I have it so that it does flash these colors, but it does them way too fast. I've been trying to delay it with "Yield" but it flashes really quickly then waits for the yield then continues to flash quickly. Please help, here is my Javascript; This code is also connected to a cube FYI.
var materials: Material[];
var randNum : int = 1;
//var waitTimeBetweenFlashes : int = 1;
function Update ()
{
waitTime();
}
function waitTime() {
if (randNum == 1)
{
var mat: Material = materials[Random.Range(0, materials.Length)];
renderer.sharedMaterial = mat;
randNum = 0;
}
if(randNum == 0){
randNum = 1;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613121739im_/https://answers.unity.com/themes/thub/images/avi.jpg)