Author Topic: UIPopupList Help (How to execute function on value selection)  (Read 4032 times)

Avagantamos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
UIPopupList Help (How to execute function on value selection)
« on: January 11, 2016, 10:02:59 PM »
Hello!  I tried reading through the NGUI documentation and past forum threads, but I can't seem to understand how to get UIPopupList to execute a function when a value is selected.  I can show you what I have tried:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ShamanBaseScript : MonoBehaviour {
  5.  
  6.  
  7.         public UIPopupList popUP;
  8.  
  9.        
  10.         void Update () {
  11.  
  12.                 if (popUP.value == "Add 1 Mana") {
  13.                     transform.rotation = Quaternion.Euler (0, 0, -90);
  14.                 }
  15.  
  16.                        
  17.         }

All I'm trying to do is say: When you select the 'Add 1 Mana' option in the popup list turn the object -90 degrees.  I feel as though there is something I'm missing.  Past threads have spoken about OnSelectionChange(); and onChange  but I have no idea how to implement these.  I would really appreciate a simple example.  Thank you!

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIPopupList Help (How to execute function on value selection)
« Reply #1 on: January 12, 2016, 01:37:54 AM »
There are several ways to implement EventDelegate.  Here is the most common:

  1. public UIPopupList popup = null;
  2.  
  3. void Start()
  4. {
  5.      EventDelegate.Add(popup.onChange, OnChange_Popup);//beware:   .Add or .Set
  6. }
  7.  
  8. public void OnChange_Popup()
  9. {
  10.      print(popup.value);
  11.      
  12.      if (popup.value == "Add 1 Mana")
  13.           transform.rotation = Quaternion.Euler (0, 0, -90);
  14. }
  15.