Guest User

Untitled

a guest
Jul 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. [RequireComponent(typeof(Dropdown))]
  2. public class SaveDropdownValue : MonoBehaviour
  3. {
  4. const string PrefName = "optionvalue";
  5.  
  6. private Dropdown _dropdown;
  7.  
  8. void Awake()
  9. {
  10. _dropdown = GetComponent<Dropdown>();
  11.  
  12. _dropdown.onValueChanged.AddListener(new UnityAction<int>(index =>
  13. {
  14. PlayerPrefs.SetInt(PrefName, _dropdown.value);
  15. PlayerPrefs.Save();
  16. }));
  17. }
  18.  
  19. void Start ()
  20. {
  21. _dropdown.value = PlayerPrefs.GetInt(PrefName, 0);
  22. }
  23. }
Add Comment
Please, Sign In to add comment