- Home /
How to load two different scenes from a single UI button using PlayerPrefs
The game contains two controls - joystick and Accelerometer which i want to switch in the settings menu. I have used PlayerPrefs to assign both the buttons in the settings menu, an integer.
For eg. for joystick
PlayerPrefs.SetInt ("Control", 1);
And for accelerometer it is 6 (both the integers are the sceneindex of the scenes). I basically want, when i click the start button it should take the value of playerprefs and load that scene. The below code is what i tried but it didnt worked.
public void LoadByIndex (int i)
{
i = PlayerPrefs.GetInt ("Control");
SceneManager.LoadSceneAsync (i);
}
,
Answer by Raimi · Jun 16, 2017 at 11:21 AM
using UnityEngine.SceneManagement;
public class SceneController : MonoBehaviour
{
void Start()
{
LoadByIndex( PlayerPrefs.GetInt("Control"));
}
public void LoadByIndex (int index)
{
SceneManager.LoadScene (index);
}
}
Answer by harrismak4 · Jun 16, 2017 at 02:37 PM
Have you added all scenes to BUILD SETTINGS -> Scenes in build ??
Your answer
Follow this Question
Related Questions
Saving for a Level Editor 1 Answer
PlayerPrefs dont worn android 0 Answers
[ANDROID]saving data with playerprefs 1 Answer
Same Playerprefs for 2 games? [Android] 1 Answer
Android Error 0 Answers