Unity/UIDropdown
提供: 初心者エンジニアの簡易メモ
2018年9月10日 (月) 10:43時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「==Dropdown追加方法== #UI/Dropdownを追加 #Dropdownを選択肢Inspectorのoptionsから選択項目を編集する ==Dropdown選択値取得サンプル== <pre> us...」)
Dropdown追加方法
- UI/Dropdownを追加
- Dropdownを選択肢Inspectorのoptionsから選択項目を編集する
Dropdown選択値取得サンプル
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
Dropdown m_Dropdown;
public Text m_Text;
void Start()
{
//Fetch the Dropdown GameObject
m_Dropdown = GetComponent<Dropdown>();
//Add listener for when the value of the Dropdown changes, to take action
m_Dropdown.onValueChanged.AddListener(delegate {
DropdownValueChanged(m_Dropdown);
});
//Initialise the Text to say the first value of the Dropdown
m_Text.text = "First Value : " + m_Dropdown.value;
}
//Ouput the new value of the Dropdown into Text
void DropdownValueChanged(Dropdown change)
{
m_Text.text = "New Value : " + change.value;
}
}
参考:https://docs.unity3d.com/ja/current/ScriptReference/UI.Dropdown-onValueChanged.html
選択項目の高さが狭い場合
templates/viewportのscaleのyを1から3とかにする
