Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Ransu on March 01, 2013, 06:45:39 PM
-
Hi, I am new to NGUI and coding so bare with me. There is a tutorial example 11 that shows a POPUP menu.
How do I get a text (label) to show texts according to the selection of the POPUP selection.
Like POPUP alternatives (1,2,3,4)
Pressing 1 - show label "1 is a number"
Pressing 2 - show label "2 is also a number"
Thankful for any help, and please explain clearly as to a noob! ;)
-
Write a script that will register to receive UISlider.onValueChange notifications and do what you want with the selection.
-
In the tutorial 11 in NGUI, I can see the following code on the SlicedSprite "X" that changes color.
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(UIWidget))]
[AddComponentMenu("NGUI/Examples/Set Color on Selection")]
public class SetColorOnSelection : MonoBehaviour{
UIWidget mWidget;
void OnSelectionChange (string val){
if (mWidget == null) mWidget = GetComponent<UIWidget>();
switch (val)
{
case "White": mWidget.color = Color.white; break;
case "Red": mWidget.color = Color.red; break;
case "Green": mWidget.color = Color.green; break;
case "Blue": mWidget.color = Color.blue; break;
case "Yellow": mWidget.color = Color.yellow; break;
case "Cyan": mWidget.color = Color.cyan; break;
case "Magenta": mWidget.color = Color.magenta; break;
}
}
}
If I add a new SlicedSprite of the X and add the code SetColorOnSelection onto it, this mew slicedsprite won´t change color?
If the UISlider.onValueChange is the solution, could someone please write the code, howto do it.
-
For the script you posted to work it needs to be attached to the drop-down list, and the drop down's list event notification function must be called SetColorOnSelection. This script works with a drop-down list, not with a slider. To listen to slider changes, use UISlider.onValueChange += YourFunction.