GUI control inside an if statement

Hey, so I am fairly new to Unity and programming in the first place, so this question could be a bit stupid, but I am stuck. I want to create a program so that when a button is clicked, another image pops up and slides horizontally across the screen. right now it looks like this: (unityscript)

//switcher and oldswitcher is the same toggle
if (oldswitcher != switcher){

      now = Time.time; 
      GUI.Box(Rect(210 + (Time.time-now)*100, 110, 50 , 20), "", mystyle);

on Unity, it doesn’t show anything, does it have to do with controls not being able to be inside an if statement?

Is this block of code inside the OnGUI function? You cannot use GUI outside of that one, and a few specific others.

Also, to only declare it once, have a variable ‘oldSwitcher’ and save switchers value in it at the end of every frame switcher = oldSwitcher. Now if( oldSwitcher!=switcher) {//switcher just changed}