Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by benk0913 · Jun 15, 2013 at 04:23 PM · guibuttonmouselayersinventory

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..

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Disable a GUI while left mouse button is Down? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges