Author Topic: Selecting one item from grid  (Read 9191 times)

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Selecting one item from grid
« on: May 14, 2013, 12:22:25 PM »
Hi. Well... my menu is almost done! One last thing I need to do. I have grid with items, and I want to be able to select between them. Like there are 4 countries, and when you click on one, it gets yellow overlay. When you click on another, the first loses its overlay, and the another one gets it. Could you please help me with script, or tell me if there's some tutorial somewhere? Thanks.


I know that this text doesn't make much sense, but I really don't know how else to say it...

wizardsmoke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 5
  • Posts: 40
    • View Profile
Re: Selecting one item from grid
« Reply #1 on: May 14, 2013, 01:04:25 PM »
BroadcastMessage would work great here since each of the buttons are children of the same game object (the grid).  Each button/country would need a script with these functions...

  1. public GameObject overlay;
  2.  
  3. void OnClick()
  4. {
  5.     transform.parent.BroadcastMessage("Select", false);
  6.     Select(true);
  7. }
  8.  
  9. void Select(bool selected)
  10. {
  11.     if (selected)
  12.     {
  13.         //turn on overlay
  14.         NGUITools.SetActive(overlay, true);
  15.     }
  16.     else
  17.     {
  18.         //turn off overlay
  19.         NGUITools.SetActive(overlay, false);
  20.     }
  21. }
  22.  

Then just drag and drop the overlay for each of the buttons into the overlay variable slot in the inspector.
Hope this helps :)

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Selecting one item from grid
« Reply #2 on: May 14, 2013, 02:10:31 PM »
Thanks. I will try that tomorrow, and post what I got.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Selecting one item from grid
« Reply #3 on: May 15, 2013, 10:55:09 AM »
Don't know, what I did wrong. I have put Button script on the items, then put the script on each of them. It just doesn't do anything. And yeah, I have put the overlay sprites into inspector.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Selecting one item from grid
« Reply #4 on: May 16, 2013, 11:51:44 AM »
Any suggestions? :(

yeagerj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Selecting one item from grid
« Reply #5 on: May 16, 2013, 01:51:07 PM »
You could also just make all the child items a UICheckbox. If they are all under the same parent (your grid) or you give them all the same radioButtonRoot, they will automatically turn on/off the overlay.

You'd probably end up having something like:

UICheckbox
->overlay image
->country image

So that would be a GameObject with a UICheckbox+collider, and then two child sprites. The overlay image should be the 'Check Sprite' of the UICheckbox.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Selecting one item from grid
« Reply #6 on: May 22, 2013, 03:59:36 AM »
I'll try it. Thanks.