Delay on thunderlight

I just copied a code from this forum and now i want some delay between the lightnings.

I’ve tried to google it and find answers here but nothing works.

     var minTime = .5;
    var thresh = .5;
    
    private var lastTime = 0;
    private var myLight;
    
    function Start()
    {
        myLight = GetComponent(Light);
    }
    
    function Update ()
    {
      if ((Time.time - lastTime) > minTime)
            if (Random.value > thresh)
                light.enabled = true;
            else
                light.enabled = false;
                    lastTime = Time.time;
        
            
    }

Anyone who knows how to fix the delay?

Thx!

You can use Invoke() or InvokeRepeating(), as Fattie said. Invoke(functionname, time; and
InvokeRepeating(functionname, delay);

Not exactly what you asked, but here’s an old lightning code I’ve written a few years ago.
Simply attach it to a directional light you want to be used as your “lightning” and configure it as you see fit.

[4570-lightning.txt|4570]

Hey all, thanks for your replies.

I must say, im still kida confused about this invoke()-thing.

How do I use it in the code above?