「Unity/UIToggle」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→チェックボタン) |
(→チェックボタン) |
||
行2: | 行2: | ||
GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = true; | GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = true; | ||
GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = false; | GameObject.Find("/Canvas/Toggle").GetComponent<Toggle> ().isOn = false; | ||
+ | |||
+ | ==変更イベント== | ||
+ | <pre> | ||
+ | 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; | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | 公式:https://docs.unity3d.com/ja/current/ScriptReference/UI.Toggle-onValueChanged.html |
2018年9月10日 (月) 15:42時点における版
チェックボタン
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