public UI.Toggle.ToggleEvent onValueChanged ;

Descripción

Callback ejecutado cuando el valor del toggle cambia.

Use this to detect when a user activates or deactivates the Toggle. Add a listener to perform an action when this Event detects a change in the Toggle state. See the delegates tutorial for more information on delegates.

//Attach this script to a Toggle GameObject. To do this, go to Create>UI>Toggle.
//Set your own Text in the Inspector window

using UnityEngine; using UnityEngine.UI;

public class Example : MonoBehaviour { Toggle m_Toggle; public Text m_Text;

void Start() { //Fetch the Toggle GameObject m_Toggle = GetComponent<Toggle>(); //Add listener for when the state of the Toggle changes, to take action m_Toggle.onValueChanged.AddListener(delegate { ToggleValueChanged(m_Toggle); });

//Initialise the Text to say the first state of the Toggle m_Text.text = "First Value : " + m_Toggle.isOn; }

//Output the new state of the Toggle into Text void ToggleValueChanged(Toggle change) { m_Text.text = "New Value : " + m_Toggle.isOn; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961