how to keep a from instantiation when b is active?

so i have two instantation scripts that i dont want to have happen at the same time how would i keep this from happening? here are the scripts:

//Tower 1 button	
		if(GUI.RepeatButton (Rect ((Screen.width - 70) - towerOneLeft,Screen.height - 65,50,50), "Tower_1") || Input.GetKeyUp("a")){
			
				isGui = true;	
           		tower1Bool = true;
           	
          	 	if(a == 0){
           		ghost1Tower = Instantiate(tower1Ghost,gridPoint.transform.position,Quaternion.identity);       		            			           			              		             				 
					a = 1;
					}
				}

//Tower 2 button	
		if(GUI.RepeatButton (Rect ((Screen.width - 70) - (towerOneLeft*2),Screen.height - 65,50,50), "Tower_2") || Input.GetKeyUp("s")){
			
			isGui = true;	
           	tower2Bool = true;
           	if(b == 0){
           	ghost2Tower = Instantiate(tower1Ghost,gridPoint.transform.position,Quaternion.identity);       		            			           			              		             				 
				b = 1;
				}      		            			           			              		             				 
			}

I don’t understand your question very well.

Your code that checks “(if b == 0)” should be ok to prevent that code to be executed more than once. Make sure the “b” and “a” variables are not local on the OnGUI function.

I’ve noticed you also have other flags, like “tower1Bool” and “tower2Bool” that could be used for the same purpose.

If this does not help, please try to rephrase and explain a bit better and I’ll try to help.

You should not use Input.GetAnythingUp/Down inside OnGUI, because these functions return true during the whole Update cycle, and OnGUI occurs several times during this cycle - thus you can have multiple events GetKeyUp/Down. Anyway, the variables a and b should prevent multiple Instantiates to occur, but they must be declared outside any function for this to work - if declared inside OnGUI, they are created each time you enter the function, and deleted when you exit, thus they never “remeber” their previous values.

But I can’t see how these Instantiates could be executed at the same time, since they are fired by two different buttons or keys - unless you press “a” and “s” at the same time, and your keyboard hardware can detect these two keys separately.