GUI Button within if statement doesn't disappear even when the if statement is false

So I’m trying to have this book that the player can flip through by pressing two different GUI buttons, one indicating right, the other left. Here is the code I have thus far:

    if (page1 == true && page2 == false && page3 == false && page4 == false && page5 == false){

  if (GUI.Button(Rect((Screen.width/100)*60, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent(">"))){

    page2 = true;
    page1 = false;
    bookmark.renderer.enabled = false;
  }
}

if (page2 == true && page1 == false && page3 == false && page4 == false && page5 == false){
    Debug.Log("Page 2 is true");   
  /*if (GUI.Button(Rect((Screen.width/100)*60, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent(">"))){ 
     page3 = true;
     page2 = false;
 }*/
  if (GUI.Button(Rect((Screen.width/100)*40, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent("<"))){
	page1 = true;
	page2 = false;
	bookmark.renderer.enabled = true;
 }}

The debug log indicated that it Page 2 does become true (it is initialized as false, so when you press the button it does make it true) but nothing else under the page2 if statement is run apparently.

Thanks in advance for any help!

EDIT MAY 30th: Here’s a screenshot of it:
[1066-Screen+shot+2012-05-30+at+10.38.48+PM.png|1066]

And this is the current code:

  if (cameraBook.enabled == true){


 //keep track of which is the current page
  var page : int = 1;

  var showLog : boolean = true;


  //this makes sure that this zoom out button only shows up when you're not looking at the bookmark
  if (zoomBookmark.bookmark == false){

     if (GUI.Button(Rect((Screen.width/100)*25, ((Screen.height/100)*60), Screen.width / 14, Screen.height/8), GUIContent("Zoom out"))){

         cameraTable.enabled = true;
         cameraBook.enabled = false;
      }
      
      if (page > 0){
         if (GUI.Button(Rect((Screen.width/100)*40, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent("<"))){
           page--; //one page back 
           showLog = true;            
         }
      }
      
      if (page < 6){
        if (GUI.Button(Rect((Screen.width/100)*60, ((Screen.height/100)*85), Screen.width/16, Screen.height/12), GUIContent(">"))){
          page++; // one page forward 
          showLog = true;           
        }
     }

      switch(page) //variable to switch
       {
       
         case 0 : //page = 0 (I know that's not following the whole natural numbers thing... but don't worry about it
           if (showLog){
             Debug.Log("Vieiwing page 0");
             showLog = false;
           }
           
           bookmark.renderer.enabled = true;
           musicSheet.renderer.enabled = false;
         case 1 : //page = 1
 
         if (showLog) //show the log for one frame, otherwise you print 2+ times per frame
          {
            Debug.Log("viewing page 1");
            showLog = false;
           }
      
               bookmark.renderer.enabled = false;
           
           break;
  
           case 2: // on page 2
  
            if(showLog){
              Debug.Log("Viewing Page 2");
              showLog = false;         
             }
           bookmark.renderer.enabled = false; 
                                                                                               
           break;
           
           case 3:
             if(showLog){
                Debug.Log("Viewing Page 3");
                showLog = false;
             }
           break;
           
           case 4: 
             if(showLog){
                Debug.Log("Viewing Page 4");
                showLog = false;
             }
           break;
           
           case 5:
             if(showLog){
                Debug.Log("Viewing Page 5");
                showLog = false;
             }
           break;
           
           case 6:
             if(showLog){                 
                Debug.Log("Viewing Page 6");
                showLog = false;
             }
             
            musicSheet.renderer.enabled = true;
           break;

        } 
        }    
        }

To make your code much neater, use a switch case. You wont need all those crazy booleans ;p and it will be much easier to read. Basically it switches between the sections of code based on the case presented. I will demonstrate with an int, which will be the page number. Then each case will be the current page.

var page:int;   //page number
var scnH:float; //screen height
var scnW:float; //screen width

private var showLog:boolean=true;

function OnGUI()
{
    switch(page) //variable to switch
    {
        case 0:  //page = 0

           //This is the default value, maybe the books cover??

        break;
        case 1:  //page = 1

            if(showLog) //show the log for one frame, otherwise you print 2+ times per frame
            {        
                Debug.Log("Viewing Page 1");
                showLog=false;
            }
            if( GUI.Button(Rect(scnW/100*60,scnH/100*85,scnW/16,scn/12),GUIContent(">")) )
            {
                page=2;
                bookmark.renderer.enabled = false;
                showLog=true;
            }

        break;
        case 2:  //page = 2

            if(showLog)
            {    
                Debug.Log("Viewing Page 2");
                showLog=false;
            }
            //Add the other buttons here

        break;
    }
}

Not sure what the problem was…, either way this will make it much easier to control your code. With a 20 page book, you wont need 20 booleans and a page long conditional :slight_smile:

Your real problem was that you “commented out” your code block for the stuff you wanted to do. This…

       if (page1 == true && page2 == false && page3 == false && page4 == false && page5 == false){
    // [...]

    if (page2 == true && page1 == false && page3 == false && page4 == false && page5 == false){
        Debug.Log("Page 2 is true");   
      /*if (GUI.Button(Rect((Screen.width/100)*60, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent(">"))){ 
         page3 = true;
         page2 = false;
     }*/
      // [...]

should actually be this…

if (page1 == true && page2 == false && page3 == false && page4 == false && page5 == false){
    // [...]

    if (page2 == true && page1 == false && page3 == false && page4 == false && page5 == false){
        Debug.Log("Page 2 is true");   
      if (GUI.Button(Rect((Screen.width/100)*60, ((Screen.height/100)*85), Screen.width / 16, Screen.height/12), GUIContent(">"))){ 
         page3 = true;
         page2 = false;
     }
      // [...]

Note: the “// […]” means part of the script is skipped.