- Home /
renderer.enabled at random, how?
How would you turn this script into random script. Renderer needs to be enable only for 0.5 Seconds and then disable.
renderer.enabled = (Time.time % 2 > 1); // This script turns renderer on for 1 second and turns off for 1 second (Mimics Flashing).
Imagine lightning flash.
Comment
Answer by mirkobon · Sep 16, 2013 at 03:40 PM
var RandomLigtning : int;
function Update () { RandomLigtning = Random.Range(0,10000)
if (RandomLigtning == 1) { renderer.enabled = (Time.time % 2 > 1); // This script turns renderer on for 1 second //and turns off for 1 second (Mimics Flashing). } }
Nope, this script does not work, it stays on till the next Random # = true, then stays off thill the next number is true. It only needs to stay on for 0.5 sec.
public int RandomLightning;
void Update () {
RandomLightning = UnityEngine.Random.Range(1,100);
if (RandomLightning == 1) GameObject.Find(SystemSizeSetup[i].name + "Lightning1").renderer.enabled = (Time.time % 2 > 1);
}
The problem is inside the true statement script " = (Time.time % 2 > 1);"
Your answer
![](https://koobas.hobune.stream/wayback/20220613114259im_/https://answers.unity.com/themes/thub/images/avi.jpg)