- Home /
 
 
               Question by 
               fredz0003 · Nov 13, 2011 at 04:08 AM · 
                guibuttonbeginnerguitexture  
              
 
              Tic Tac Toe beginner
So I am making a tic tac toe I borrowed the art from igamemaker.com I followed his video but he lost me with the code, I programmed tic tac toe in c++ and it is not that complicated as his code looked. So anyways I initialized the gui board background and initialized the 9 gui buttons set them to empty state, I am kinda lost with out a main function, since on my c++ program I had getmove1 and getmove2 for both human players and placed that in main, how can I implement a player turn function on this tic tac toe GUI here's my code and thanks in advance. basically what I have done so far is when the user clicks on the button it changes the texture according to the active player I think I lost my way in this GUI world.
 //declaring all states of buttons
 var emptyState : Texture;
 var xPlayer : Texture;
 var oplayer : Texture;
 
 //var to help to move buttons to see coordinates
 var xpos = 10;
 var ypos = 10;
 
 //player turn variables
 var activePlayer = 0;
 
 var customGUIskin : GUISkin;
 var background : Texture2D;
 
 var board = new int[3,3];
 
 //declaring all buttons to emptyState
 
 private var button1 : Texture;
     button1 = emptyState;
 private var button2 : Texture;
     button2 = emptyState;
 private var button3 : Texture;
     button3 = emptyState;
 private var button4 : Texture;
     button4 = emptyState;
 private var button5 : Texture;
     button5 = emptyState;
 private var button6 : Texture;
     button6 = emptyState;
 private var button7 : Texture;
     button7 = emptyState;
 private var button8 : Texture;
     button8 = emptyState;
 private var button9 : Texture;
     button9 = emptyState;
     
 
 
 function awake()
 {
     
 }
 
 function OnGUI()
 {
     
     
     GUI.skin = customGUIskin;
     
     GUI.Label(Rect(0,0,320,480), GUIContent(background));
     
     if (!emptyState) 
     {
      Debug.LogError("Please assign a texture on the inspector");
      return;
     }
     
     
     //Top Row
     if(GUI.Button(Rect(13,79,94,94),button1))
     {
         if(activePlayer == 1)
         {
             button1 = xPlayer;
             board[0,0]= activePlayer;
             
         }
         
     }
         
     if(GUI.Button(Rect(13,79,94,94),button1))
     {
         if(activePlayer == 2)
         {
             button1 = oplayer;
             board[0,0]= activePlayer;
             
         }
         
         
         
 
     }
     
     if (GUI.Button(Rect(113,79,94,94),button2))
     {
         if(activePlayer == 1)
         {
             button2 = xPlayer;
             board[0,1]= activePlayer;
             
         }
         
     }
     
     if (GUI.Button(Rect(213,79,94,94),button3))
     {
         if(activePlayer == 1)
         {
             button3 = xPlayer;
             board[0,2]= activePlayer;
             
         }
         
         
     }
     
     //Middle Row
         if (GUI.Button(Rect(13,179,94,94),button4))
     {
         
     }
     
     if (GUI.Button(Rect(113,179,94,94),button5))
     {
         
     }
     
     if (GUI.Button(Rect(213,179,94,94),button6))
     {
         
     }
     
     //Bottom Row
     
     if (GUI.Button(Rect(13,279,94,94),button7))
     {
         
     }
     
     if (GUI.Button(Rect(113,279,94,94),button8))
     {
         
     }
     
     if (GUI.Button(Rect(213,279,94,94),button9))
     {
         
     }
     
     //Debug.Log("Clicked the button with an image");
     
     //if (GUI.Button(Rect(10,70,50,30),"Click"))
     //Debug.Log("Clicked the button with text");
     
     
 }
 
              
               Comment
              
 
               
              Your answer