Flashing REC button

so im trying to make this GUI flash repeatedly for as long as the game runs but what happens is it flashes once and stops… this is what i have:

var mainGUI : GUITexture;
var recswitch : float = 1f;
var recon = true;
var recbut1 : Texture2D;
var recbut2 : Texture2D;

function Update () {

		recswitch -= Time.deltaTime;

	if (recswitch <= 0.0f)
	{
		if (recon == true)
		{
			recon = false;
			mainGUI.texture = recbut2;
			recswitch = 2f;
		}
		else if (recon == false)
		{
			recon = true;
			mainGUI.texture = recbut2;
			recswitch = 2f;
		}
}

You’ve got a copy and paste error, it looks like. You’re assigning the same texture in both places.

FYI, an easier way to toggle a boolean would be “recon = !recon”.

Er… could you explain how I would do a recon = !recon? Im pretty new at this and just piecing together what I pick up from tutorials…

In this case it’s not actually any easier, since you have to do other stuff at the same time as well. But yes, the issue at a glance would appear to be that you’re using the same texture for both states.

waiit…OMG I get what your saying now!!! Ah… wow… Two terribly simple mistakes in the same night T_T thanks guys I would never have spotted that… I feel silly now

It’s all good, I know that feeling all too well. :wink:

You can use the “!” character as a shorthand for “myVariable == false.” It’s pretty common, so it’s good to know.

These are really style issues, but it’s good to know alternate ways of expressing things, especially when you look at other people’s code. For instance, I’d have written your update like this:

function Update () 
{

    recswitch -= Time.deltaTime;

    if (recswitch <= 0.0f)
    {
        recswitch = 2f;
        recon = !recon;
        mainGUI.texture = (recon) ? recbut1 : recbut2;
     }
}

There’s no “correct” way to do it; what you’ve got is perfectly fine. But once you get used to some of the syntax, you’ll develop your own “style” that’s more readable and natural to you.