x


Cannot Get Light To Flash - Help

Hello,

I have a beacon light within a game object on my scene. What I want it to do is simply flash on and off every second, but its just not doing anything - it just remains on.

Here is my script:

var BeaconLight : Light;
var Triggered : boolean = false;
var WarningSound : AudioClip;

function Start(){
    InvokeRepeating("Beacon", 0, 1);
}   

function Beacon(){
    BeaconLight.light.intensity = 1;
    yield WaitForSeconds(1);
    BeaconLight.light.intensity = 0;
    return;
}

I also tried using: BeaconLight.enabled = false;

I have a feeling its to do with my timer, and how it gets invoked?

Please help me out.

Thank, Ollie

more ▼

asked Dec 12 '10 at 09:25 PM

oliver-jones gravatar image

oliver-jones
2.5k 207 226 257

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

1 answer: sort oldest

You can't use InvokeRepeating for coroutines. You don't need to explicitly set 1 or 0 anyway; you can just alternate between them, so the function doesn't need to be a coroutine.

// Use lowercase for variable names; it's less confusing
var beaconLight : Light;
var triggered : boolean = false;
var warningSound : AudioClip;

function Start(){
    beaconLight.intensity = 0;
    InvokeRepeating("Beacon", 0, 1);
}   

function Beacon(){
    // beaconLight is already a Light, so you don't need to refer to .light
    beaconLight.intensity = 1-beaconLight.intensity;
    // You don't need "return" at the end of functions. They stop anyway.
}
more ▼

answered Dec 12 '10 at 10:29 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

Thanks for the reply, but its not flashing -- its just staying on!?

Dec 12 '10 at 10:43 PM oliver-jones

Oh, sorry - it does work, just me being a numpty

Dec 12 '10 at 10:45 PM oliver-jones
(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:

x445
x356
x278
x66
x53

asked: Dec 12 '10 at 09:25 PM

Seen: 808 times

Last Updated: Dec 12 '10 at 09:25 PM