Unity/UIToggle
提供: 初心者エンジニアの簡易メモ
チェックボタン
GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = true; GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = false;
変更イベント
using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { Toggle m_Toggle; public Text m_Text; void Start() { m_Toggle = GetComponent<Toggle>(); m_Toggle.onValueChanged.AddListener(delegate { ToggleValueChanged(m_Toggle); }); m_Text.text = "First Value : " + m_Toggle.isOn; } void ToggleValueChanged(Toggle change) { m_Text.text = "New Value : " + m_Toggle.isOn; } }
公式:https://docs.unity3d.com/ja/current/ScriptReference/UI.Toggle-onValueChanged.html