• 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
1
Question by darkhog · Jan 29, 2015 at 05:52 PM · uiinventory

[4.6 GUI] Selectable list of object for things like inventory, etc.

I feel like I'm getting nowhere with it. I'm trying to make a widget for inventory/whatever items. Each item can be selected with mouse by clicking it. The only problem? It get unselected right when player clicks something different.

Because of it I've decided to reselect it once it gets deselected. But it doesn't work, I send message, not via SendMessage, obviously, to parent to decide which child object should be reselected. At first I've thought the code actually doesn't execute, but it does. It simply doesn't highlight it back.

Here's the code:

     public void ensureSelection() {
         //this function will crawl through the child widgets and reselect one with proper ID. Might be laggy
         //for categories with large amount of objects, however we'll worry about that if it start to give
         //issues.
         GameObject child;
         
         for (int i=0;i<this.transform.childCount;i++) {
             child = this.transform.GetChild(i).gameObject;
             ObjectSelectionWidgetMeta oswm = child.GetComponent<ObjectSelectionWidgetMeta>();
             if (oswm!=null) { 
                 if (oswm.ID==LevEditGlobals.currentObject){ //woohoo, found widget with our ID!
                     Selectable sel = child.GetComponent<Selectable>();
                     if (sel!=null){
                         sel.Select();
                         Debug.Log("Selected!");
                     } //selecting it.
                     break;    //we've found it so we can break out of for early, no real need to loop thru rest
                             //of children now we found proper one.
                 }
             }
         }
     
     }




And before anyone asks, yes I've thought about using Toggles with togglegroups, but they require graphic for "toggled" thing. I need color tint.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

UI: Dynamically sized inventory window with scroll 0 Answers

Is it Possible To make inv system 2 Answers

Inventory System - Find Empty Slot 2 Answers

Item and Inventory for a RPG game 2 Answers

making prefabs at runtime? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges