Can't get PitStop function working with WaitForSeconds

Hi there,

For some reason I can’t get the following to work. I want the pitstop area to take 1 pt off the damage every second… but it takes it all in one go. I am calling this from inside Update… is this the problem? I can’t see how else I could call it though as I need to check repeatedly if the car is in the pits…

function PitStop()

{

	if (g_fSpeed <= 0.1f && iPlayerOneDamage > 0)

	{

		--iPlayerOneDamage;

		yield WaitForSeconds(1.0f);

		

		// Print damage to console

		print("Player Damage" + iPlayerOneDamage);

	}

}

Okay, I fixed it… used a good old For Loop :wink:

function PitStop()

{

	if (g_fSpeed <= 0.1f)

	{

		for (var i = (iPlayerOneDamage - 1); i > 0; --i)

		{

			yield WaitForSeconds(2);

			iPlayerOneDamage = i;

		}	

		// Print damage to console

		print("Player Damage" + iPlayerOneDamage);

	}

}

I could be wrong because I don’t use javascript at all, but I don’t think you need to use the ‘f’ cast on decimal based numbers when using Unity’s javascript.

Take the f out of your floats and see if that fixes it.