- Home /
Button being pressed but an other button gets the effect.
I have a small problem with my inventory system, When people press the right mouse button on a guilayout button it turns a bool to true and that bool opens a description box with a few buttons on it. The description box is shown above the inventory so theres no problem displaying it. The problem is that when I press on a button in this description box it does the effect of the regular inventory button behind it. Which closes the description box.. I figured that out because the buttons effect works when the description box is shown next to the inventory layout and not ON it.
CODE:
 void OnGUI()
     {
         
         //Displays the inventory window.
         if(display)
         {
             
             a=0;
             GUILayout.BeginArea(rect,background1);
             for(int i = 0; i < 4; i++)
             {
                 GUILayout.BeginHorizontal();
                 for(int j = 0; j < 4; j++)
                 {
                     GameObject tempItem = (GameObject) Resources.Load(GetComponent<I_idList>().GetItemInfo(GetComponent<P_localInfo>().items[a]));
                     
                     if(GUILayout.Button(tempItem.GetComponent<I_info>().itemIcon , GUILayout.MaxWidth(60),GUILayout.MaxHeight(60)))
                     {
                         
                          if (Event.current.button == 0)//Left Click
                             showDiscBox=false;
                             else if (Event.current.button == 1)//Right Click-Shows item description, sets the currect item selected.
                         {
                             showDiscBox=true;
                             rectOfDiscBox=new Rect(Event.current.mousePosition.x,Event.current.mousePosition.y,250,250);
                             lastitemPressed=tempItem;
                             savedSpot=a;
                         }
                         
                     }
                     
                     a++;
                 }
                 GUILayout.EndHorizontal();
 
             }
             GUILayout.EndArea();
             
             
             
             if(showDiscBox)
                 {//The description box will show the items options
                     GUILayout.BeginArea(rectOfDiscBox,background2);
                         GUILayout.BeginArea(new Rect(25,25,200,200));
                         GUILayout.Box (lastitemPressed.GetComponent<I_info>().itemName);
                         
                             GUILayout.BeginHorizontal();
                                 GUILayout.Label(lastitemPressed.GetComponent<I_info>().itemDescription);
                             GUILayout.EndHorizontal();
                         
                             GUILayout.BeginHorizontal();
                                 if(GetComponent<P_localInfo>().items[savedSpot]!="000")
                                 {
                                     if(GUILayout.Button ("Drop"))
                                     {
                                             //Removes the item, updates the database and resets the discription box.
                                             GetComponent<P_localInfo>().items[savedSpot]="000";
                                             StartCoroutine(GetComponent<P_control>().CORE.GetComponent<DB_negotiation>().InventoryInfoSend(GetComponent<P_control>().CORE.GetComponent<CORE_clientinfo>().username));
                                             lastitemPressed=null;
                                             showDiscBox=false;
                                     }
                                 }
                             GUILayout.EndHorizontal();
                             GUILayout.BeginHorizontal();
                     
                                 if(lastitemPressed.GetComponent<I_info>().itemType==1)//Useable items.
                                 {
                                     if(GUILayout.Button ("Use"))
                                     {
                                         //Removes the item, updates the database and resets the discription box.
                                         if(GetComponent<P_localInfo>().items[savedSpot]=="001")//Checks if water, to leave an empty bottle.
                                             GetComponent<P_localInfo>().items[savedSpot]="002";
                                         else
                                             GetComponent<P_localInfo>().items[savedSpot]="000";
                                         
                             
                                             //The effect of the item
                                             lastitemPressed.GetComponent<I_useable>().Effect(this.gameObject);
                                             
                             
                                         StartCoroutine(GetComponent<P_control>().CORE.GetComponent<DB_negotiation>().InventoryInfoSend(GetComponent<P_control>().CORE.GetComponent<CORE_clientinfo>().username));
                                         lastitemPressed=null;
                                         showDiscBox=false;
                                     }
                                 }
                     
                                 else if(lastitemPressed.GetComponent<I_info>().itemType==3)//Rifles
                                 {
                                         if(GUILayout.Button ("Equip"))
                                         {
                                 
                                             //Load the item.
                                             
                                             callEquipItem(PhotonTargets.Others,lastitemPressed.GetComponent<I_info>().itemName);
                                             
                                             if(photonView.isMine)
                                             equipItem(lastitemPressed.GetComponent<I_info>().itemName);
                             
                             
                                             GetComponent<P_animation>().chestState=0;
                                             StartCoroutine(GetComponent<P_control>().CORE.GetComponent<DB_negotiation>().InventoryInfoSend(GetComponent<P_control>().CORE.GetComponent<CORE_clientinfo>().username));
                                             lastitemPressed=null;
                                             showDiscBox=false;
                                         }
                                     
                                 }
                             GUILayout.EndHorizontal();
                         GUILayout.EndArea();
                 GUILayout.EndArea();
                 
             }
             
         }
             
 
         
     }
Its long as hell, I know. but I didnt know what to put and what not to..
Your answer
 
 
             Follow this Question
Related Questions
GUI Button to create another GUI 1 Answer
Right-click button using GUI class? 3 Answers
GUI grid of buttons issue. 1 Answer
Menu button needs to be double clicked. 4 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                