Count not working correctly with Input.GetKeyUp

hey guys easiest way to explain this is i need the same key to make different gui boxes hold different pictures depending on the current count. the error is in my Update() function. for some reason even though I have Get KeyUp (meaning it only registers when the key is released??) the count still hits 3 in 1 press meaning that it changes all 3 textures at the same time (1 press of Q). What I want to happen is the first time I press Q buff1 changes and the next time I press Q buff2 changes and then the next time buff 3 changes then it goes back to the first picture. I cant see the error in my code. please help!

cheers

var exort : Texture2D;
var quas : Texture2D;
var wex : Texture2D;
var sunStrike : Texture2D;
var chaosMeteor : Texture2D;
var forgedSpirit: Texture2D;
var emp : Texture2D;
var defeaningBlast : Texture2D;
var tornado : Texture2D;
var alacrity : Texture2D;
var iceWall : Texture2D;
var coldSnap : Texture2D;
var ghostWalk : Texture2D;
var invoke : Texture2D;

var buff1 : Texture2D;
var buff2 : Texture2D;
var buff3 : Texture2D;

var count : int;

function Start()
{
	count = 1;
}

function Update()
{
	if(Input.GetKeyDown("q"))
	{
		if(count == 1)
		{
			buff1 = exort;
			count ++;
			print("1" + count);
			if(count > 3)
			{
				count = 1;
			}
		}
		if(count == 2)
		{
			buff2 = exort;
			count ++;
			print("2" + count);
			if(count > 3)
			{
				count = 1;
			}
		}
		if(count == 3)
		{
			buff3 = exort;
			count ++;
			print("3" + count);
			if(count > 3)
			{
				count = 1;
			}
		}
		
	}
}

function OnGUI ()
{	
	GUI.Box (Rect (405,400,70,70),invoke); /// Invoke always same texture	R
	GUI.Box (Rect (165,400,70,70),quas);//Quas Wex Exort	Q	always same texture
	GUI.Box (Rect (245,400,70,70),wex);//Quas Wex Exort	W		always same texture
	GUI.Box (Rect (325,400,70,70),exort);//Quas Wex Exort	E	always same texture
	
	GUI.Box (Rect (315,300,50,50),buff1);
	GUI.Box (Rect (375,300,50,50),buff2);
	GUI.Box (Rect (435,300,50,50),buff3);	
				
	GUI.Box (Rect (485,400,70,70),"5");//Spells D
	GUI.Box (Rect (565,400,70,70),"6");//Spells	F
}

Maybe I’m blind or something but it indicates GetKeyDown right? So what was your question again?

Hellow.
In your code you are using GetKeyDown but is not the problem.

the problem is that in the Update, you have 3 ifs and if u see them…

You press down the key (or up if u put GetKeyUp)

count = 1 → 1st if is true … → in this if, count is increased so now is count = 2
count = 2 → 2nd if is true … → in this if, count is increased so now is count = 3
count = 3 → 3rd if is true … → the three “ifs” are processed in the same key pressing because they are all true.

I hate when I spend an hour on something simple then I post it on here and I instantly get it. Ill give my answer incase any else gets an error like this.

In the update the second 2 if functions needed to be else if not if.

The solution is ussing " else if " in the second and third " ifs "

thanks man I got it before i refreshed the page lols, cheers for the fast reply anyways. your explanation is quite good.

hahaha, yes i see.

good luck with ur game.