Created
July 15, 2018 19:28
-
-
Save codehoose/daa8ea19f142d4453e9a3bd6bd4b77b1 to your computer and use it in GitHub Desktop.
Code from the video https://youtu.be/3NzNIsJO2Hs. Saves the dropdown's selected item to playerprefs & reloads the value when the game restarts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [RequireComponent(typeof(Dropdown))] | |
| public class SaveDropdownValue : MonoBehaviour | |
| { | |
| const string PrefName = "optionvalue"; | |
| private Dropdown _dropdown; | |
| void Awake() | |
| { | |
| _dropdown = GetComponent<Dropdown>(); | |
| _dropdown.onValueChanged.AddListener(new UnityAction<int>(index => | |
| { | |
| PlayerPrefs.SetInt(PrefName, _dropdown.value); | |
| PlayerPrefs.Save(); | |
| })); | |
| } | |
| void Start () | |
| { | |
| _dropdown.value = PlayerPrefs.GetInt(PrefName, 0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment