Stroboscoop [SOLVED]

Hello,

I’m looking for a working Stroboscoop script, as I can’t seem to figure out how to do it!

Right now I have the following piece of code;

	while (Input.GetKey("m")) {
          light.intensity = 0;
          WaitForSeconds (0.1);
          light.intensity = 1;
          WaitForSeconds (0.1);
          yield;
	}

Anyone know how? :slight_smile:

Thanks in Advance.

function LightChange ()
{
   light.intensity = 0.0;
   WaitForSeconds (0.1);
   light.intensity = 1.0;
}

Thanks for your help!

One pity though, it doesn’t seem to do anything!

var Strobo = 0;

InvokeRepeating("LightChange", 2, 0.3);

function LightChange ()
{
   light.intensity = 0.0;
   WaitForSeconds (0.1);
   light.intensity = 1.0;
}

function Update () {

if (Strobo == 1) {
LightChange();
}
if (Strobo == 0) {
light.intensity = 0;
}
	
if (Input.GetKeyDown("6")) {
if (Strobo == 1) {
Strobo = 0;
}else{
Strobo = 1;
}
}
}

Any idea what could be wrong with this? No errors what so ever.

I don’t understand what you exactly want, to be honest. Explain again, please (the wanted behavior).

I want to make a Spotlight to act as a Stroboscoop.

The white flickering (Flashing) lights which you see in disco’s or music events.

So the light should go ON and OFF very quickly to get this effect.

function Update()
{
   LightChange ();
}


function LightChange ()
{
   light.intensity = 0.0;
   WaitForSeconds (0.1);
   light.intensity = 1.0;
}

Also doesn’t work (I’m using Unity 3 F1)

Oh dear, maybe a bug in F1?

I also tried using FixedUpdate instead of Update, but in both cases, no effect.

The light keeps solid white.

does this work?

function Start () {
     while (true) {
          yield WaitForSeconds(0.05);
          light.intensity = 0;
          yield WaitForSeconds(0.05);
          light.intensity = 1;
     }
}

EDIT: Yup, this one does work, thanks alot !! :twisted:

private var stroboscopeOn : boolean = false;
public var durationOn : float = 0.1;
public var repeatTime : float = 2.0;
public var button : String = "o";

function Update ()
{
	if (Input.GetKeyDown (button))
	{
		stroboscopeOn = !stroboscopeOn;
		if (stroboscopeOn)
			InvokeRepeating ("LightChange", 0.0, repeatTime);
		else
			CancelInvoke ();
	}
}

function LightChange ()
{
	light.intensity = 1.0;
	yield new WaitForSeconds (durationOn);
	light.intensity = 0.0;
}

Edit : double-crossed while thinking :frowning:

oh yeah, forgot yield in front of waitforseconds…sorry

or :

function Start() 
{ 
   InvokeRepeating("LightChange", 0.0, 1.0);
} 

function LightChange () 
{ 
   if(light.intensity == 0.0)
   light.intensity = 1.0;
   else
   light.intensity = 0.0;
}