public bool isOn ;

描述

返回或设置 Toggle 是否处于 on 状态。

返回此 Toggle 是处于 on 还是 off 状态。请参阅委托教程页面了解有关委托的更多信息。

//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, and output the state m_Toggle.onValueChanged.AddListener(delegate { ToggleValueChanged(m_Toggle); });

//Initialize the Text to say whether the Toggle is in a positive or negative state m_Text.text = "Toggle is : " + m_Toggle.isOn; }

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