x


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.
        }
}
more ▼

asked Jul 21 '11 at 03:56 AM

KTP gravatar image

KTP
1 1 1 1

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

2 answers: sort voted first

You would just set blinkSecond=3; again after the 'while' finishes. Or before it begins.

more ▼

answered Jul 21 '11 at 06:46 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

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

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

more ▼

answered Jul 21 '11 at 05:01 AM

jahroy gravatar image

jahroy
3.2k 14 18 41

(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:

x3458
x821
x532
x293
x167

asked: Jul 21 '11 at 03:56 AM

Seen: 1464 times

Last Updated: Jul 21 '11 at 06:46 AM