Blinking Script

Hello!

I would like an object to blink for 3 seconds. I have wrote the following code, but Unity is not entering to function blinking(). What do I do wrong?

var blinkTime : int = 3;			//How long the sphere will blink


function Start() 
{
	InvokeRepeating("blinking", 1, 1);
}

function blinking()
{
	print(blinkTime);
	blinkTime--;
	print(blinkTime);
	if (blinkTime == 0)
	{
		Object.Destroy(Object.name);
	}
	else
	{
		yield WaitForSeconds(0.5);
		renderer.enabled = false;
		yield WaitForSeconds(0.5);
		renderer.enabled = true;
	}
}

Thanks!

Coroutines can’t be used with InvokeRepeating, but you don’t need to use a coroutine anyway.

function Start() 
{
	InvokeRepeating("Blinking", 1, .5);
}

function Blinking()
{
	renderer.enabled = !renderer.enabled;
	if (--blinkTime == 0)
	{
		Destroy(gameObject);
	}
}

–Eric

1 Like

Thamls! :slight_smile: