Unity/UIRadio
提供: 初心者エンジニアの簡易メモ
toggleGroupを使ってradio選択を行う
isOnをfalseにして、共通のtoggleGroupを、toggleのgroupへ設定する
サンプル
GameObject aToggleObj = GameObject.Find("AToggle"); GameObject bToggleObj = GameObject.Find("BToggle"); GameObject cToggleObj = GameObject.Find("CToggle"); GameObject canvasObj = GameObject.Find("Canvas"); aToggleObj.GetComponent<Toggle>().isOn = false; bToggleObj.GetComponent<Toggle>().isOn = false; cToggleObj.GetComponent<Toggle>().isOn = false; ToggleGroup toggleGroup = canvasObj.AddComponent<ToggleGroup>(); aToggleObj.GetComponent<Toggle>().group = toggleGroup; bToggleObj.GetComponent<Toggle>().group = toggleGroup; cToggleObj.GetComponent<Toggle>().group = toggleGroup;