Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 redspider22 · Oct 08, 2013 at 01:33 PM · guieventinventory systemright clickleftmouseclick

Inventory GUI

Hello,

I am trying to create an inventory system and GUI using UnityGUI.

So far I have an array of invetory Items witch contains GUIContent objects with a texture and name of each object. I first tried to use a SelectionGrid but that didn't display the correct selection and I was trying to make it functionate so if I left click on a button I consume the item and if I right click on the item I drop it.

I am now trying to do this by creating first a group and in side of it having smaller groups in which I display the texture and the text. I save the smaller groups rectangles and try to use those to check if I click inside them, but the clicks don't register correctly, I initially don't get anything and then I receive a bunch of random click messages.

The following code is what I use to display the gui and check for clicks, this is called in an OnGUI() function.

 public void drawInventoryGUI(int windowId)
     {
         GUI.FocusWindow(windowId);
         GUI.BeginGroup(new Rect(windowPosition.x,windowPosition.y,windowSize.x,windowSize.y));
         
         if(!checkNoInventory()){
             scroll = GUI.BeginScrollView(new Rect(scrollPosition.x,scrollPosition.y,scrollSize.x,scrollSize.y),scroll,new Rect(0,0,scrollSize.x,enlargeFactorScrollEquipment * inventoryItem.Length/xGrid));
             //clickedItem = GUI.SelectionGrid(new Rect(gridPosition.x,gridPosition.y,gridSize.x,enlargeFactorGridEquipment * inventoryItem.Length/xGrid),clickedItem,inventoryItem,xGrid);
             drawRectGUI();
             GUI.EndScrollView();
         }
         
         
         
         GUI.EndGroup();
         
     }
     
     private void drawRectGUI()
     {
         buttonPosition = new Rect[inventoryItem.Length];
         int i=0;
         int j=0;
         GUI.BeginGroup(new Rect(gridPosition.x,gridPosition.y,gridSize.x,enlargeFactorGridEquipment * inventoryItem.Length/xGrid));
         foreach(GUIContent item in inventoryItem)
         {
             if(i%5 == 0) 
             {
                 j++;
                 i = 0;
             }
             buttonPosition[i] = new Rect(i*100,j*100,60,90);
             GUI.BeginGroup(buttonPosition[i]);
             GUI.DrawTexture(new Rect(0,0,50,50),item.image);
             GUI.Label(new Rect(0,55,50,10),item.text);
             GUI.EndGroup();
             //Debug.Log(buttonPosition[i].ToString());
             i++;
         }
         GUI.EndGroup();
         
         for(int k=0 ; k< buttonPosition.Length ; k++)
         {
             
             if(Event.current.isMouse && buttonPosition[k].Contains(Event.current.mousePosition))
             {
                 Debug.Log("Clicked on button " + k);
             }
         }
     }

Does anybody have any idea on how to do it?

Comment
Add comment · Show 1
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
avatar image Sisso · Oct 08, 2013 at 02:21 PM 0
Share

http://answers.unity3d.com/page/newuser.html

a) Asking someone to write some script for you

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

16 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 avatar image avatar image

Related Questions

Emulate RightArrow GUI Event 0 Answers

How to add UnityEvent using Custom Inspector? 1 Answer

OnGUI Event 0 Answers

EditorWindow not properly drawing 1 Answer

Prevent a click from going through GUI buttons. 7 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