Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using TMPro;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using static TMPro.TMP_Dropdown;
- public class DropDownSelect : MonoBehaviour
- {
- void Update ()
- {
- TMP_Dropdown dropMusics = GetComponent<TMP_Dropdown>();
- if (dropMusics.IsExpanded && EventSystem.current.currentSelectedGameObject != null)
- {
- string selected = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>()?.text;
- Scrollbar scroll = GameObject.Find("Dropdown List").GetComponentInChildren<Scrollbar>();
- int count = 0;
- foreach (OptionData pos in dropMusics.options)
- {
- if (pos.text == selected)
- {
- scroll.value = 1f - ((float)count / (dropMusics.options.Count-1));
- break;
- }
- count++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment