x


Lightning flash

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

more ▼

asked Jan 15 '11 at 12:15 AM

user-7337 (google) gravatar image

user-7337 (google)
46 5 6 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
        else
            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.

more ▼

answered Jan 15 '11 at 01:13 AM

DaveA gravatar image

DaveA
26.4k 151 171 256

You are my hero...works flawlessly :)

Jan 15 '11 at 08:14 PM user-7337 (google)

How memory intensive, is this approach? As in toggling enabling this fast, this often? And creds for provindg a full script to the poster.

Feb 05 at 08:55 PM Deeweext

It should take about zero memory. It's just enabling/disabling the light, with a tiny amount of script. It should be able to do this once per frame, so depends on your setup, 100/second?

Feb 08 at 11:26 PM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x30
x16
x12

asked: Jan 15 '11 at 12:15 AM

Seen: 2418 times

Last Updated: Feb 08 at 11:26 PM