Advertisement
Guest User

DropdownHandler.cs 2024-01-07

a guest
Jan 7th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6.  
  7. public class DropdownHandler : MonoBehaviour
  8. {
  9. TMP_Dropdown myDrop;
  10. public Button startButton;
  11. public GameObject block;
  12.  
  13. List<string> m_DropOptions = new List<string>
  14. {
  15. "H003",
  16. "H004",
  17. //a bunch of items here...
  18. };
  19. void Start()
  20. {
  21. myDrop = GetComponent<TMP_Dropdown>();
  22. myDrop.ClearOptions();
  23. myDrop.AddOptions(m_DropOptions);
  24.  
  25.  
  26. Button btn = startButton.GetComponent<Button>();
  27. btn.onClick.AddListener(Target);
  28. }
  29.  
  30. public void Target()
  31. {
  32. int selectedIndex = myDrop.value;
  33. string selectedOption = m_DropOptions[selectedIndex];
  34. switch (selectedOption)
  35. {
  36. case "H003":
  37. block.transform.position = new Vector3(77.5699997F, 1.533329F, -19.3199997F);
  38. break;
  39.  
  40. case "H004":
  41. block.transform.position = new Vector3(77.9100037F, 1.533329F, -20.8299999F);
  42. break;
  43.  
  44. //a bunch of cases here...
  45. }
  46. }
  47.  
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement