- Home /
Question by
KTP · Jul 21, 2011 at 03:56 AM ·
javascriptvariablebeginnerreset
How do I reset a variable?
Here's a portion of the code I'm applying to a simple sphere. I want to know how to reset the variable blinkSecond, if possible. If it isn't possible, I'd like to know if there's a way to loop this so that each time I call upon blinkSecond I can have the circle blink. I can post the rest of the code if it is needed to clarify what I'm asking. Thanks a lot!
var blinkSecond : int = 3;
function secondBlink ()
{
if (onlyCircle == true)
{
while (blinkSecond > 0)
{
blinkSecond--;
yield WaitForSeconds(0.5);
renderer.enabled = false;
yield WaitForSeconds(0.5);
renderer.enabled = true;
}
yield WaitForSeconds(.5); // wait another sec.
}
}
Comment
Best Answer
Answer by DaveA · Jul 21, 2011 at 06:46 AM
You would just set blinkSecond=3; again after the 'while' finishes. Or before it begins.
Answer by jahroy · Jul 21, 2011 at 05:01 AM
I believe you want to do something like this:
var isWindowDisplayed : boolean = true;
var functionName : String = "callMeAgainAndAgain";
var startTime : float = 3.0;
var repeatFrequency : float = 3.0;
function Start ()
{
InvokeRepeating(functionName, startTime, repeatFrequency);
}
function callMeAgainAndAgain ()
{
isWindowDisplayed = ! isWindowDisplayed;
}
Here's what the doc says:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html