Lightning flash

I need a full script that can flash a light at random intervals for lightning simple as that

This is a real quick idea, you'll want to play with the numbers, but you should get the ideas. Attach to a DirectionalLight I would think.

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;
            light.enabled = false;
    lastTime = Time.time;

thresh is the minimum threshold between 0 and 1 that a random number must exceed to turn the light on. minTime is the minimum time interval to check that random number.

A more realistic effect might have a 'strike check' time (between 'strikes') and each strike would be 'on' for some small amount of time, during which rapid flashing would take place. I'll leave that to you.

Here is a java script for Lightning and Thunder.

public var offMin : float= 10;
public var offMax : float= 60;
public var onMin : float=0.25;
public var onMax : float= 0.8;
public var l : Light;
public var Thunder : AudioClip[];

function Start() 

function light()
		yield WaitForSeconds(Random.Range(offMin, offMax));
		l.enabled = true;
		yield WaitForSeconds(Random.Range(onMin, onMax));
		l.enabled = false;

function soundfx()
	yield WaitForSeconds(Random.Range(0.25,1.75));