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 mToggle; public Text mText; void Start() { mToggle = GetComponent<Toggle>(); mToggle.onValueChanged.AddListener(delegate { ToggleValueChanged(mToggle); }); mText.text = "First Value : " + mToggle.isOn; } void ToggleValueChanged(Toggle change) { mText.text = "New Value : " + mToggle.isOn; } }
公式:https://docs.unity3d.com/ja/current/ScriptReference/UI.Toggle-onValueChanged.html