Author Topic: Question on PopUp List  (Read 3033 times)

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Question on PopUp List
« on: May 10, 2014, 08:46:04 AM »
Nearly I need to use popup list but I encounter some problems on using it.

1. How to listen the events of selecting one of the option in popup list? If I select one of them, then do something?

2. How to add and delete one option in runtime?

3. Can the default selection be null ?

Thanks for any kind of helps.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on PopUp List
« Reply #1 on: May 11, 2014, 12:31:25 AM »
1. The popup list has an On Change notification you can set.

2. UIPopupList.items.Add, Remove. It's just a list.

3. Sure. Set UIPopupList.value to null.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Question on PopUp List
« Reply #2 on: May 11, 2014, 05:25:17 AM »
I still do not understand how to listen the events of selecting one option.

How the OnValueChange can help me to do something that if I select different selection?

For example, if I simply want to Debug.Log("1") when selecting "First", and Debug.Log("2") when selecting "Second"......

How the OnValueChange can help me on this case?

Moreover, the default selection on start seems to follow by the setting on the inspector and so I can not take the default selection be null even if I use scripting that UIPopupList.value = null. I can not set it in the inspector too.
« Last Edit: May 11, 2014, 05:46:09 AM by Tomleung »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on PopUp List
« Reply #3 on: May 11, 2014, 08:22:04 AM »
Did you try using it at all?
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.     public void LogMyValue ()
  6.     {
  7.         Debug.Log(UIPopupList.current.value);
  8.     }
  9. }
Attach that script to any object. Choose this game object and LogMyValue function in the On Change field in the popup list inspector. Click Play and choose some value from the popup list.