Question by
Bellatorpoeta · Oct 04, 2017 at 03:47 PM ·
arrayplayerprefssave datalevelslevel select
How can I save values in an array using PlayerPrefs?
I'm trying to create a method where the value in an array for unlocking levels is checked to see if it has been unlocked. I have two arrays, one for levels and one for unlocking, and when a button for the next level is pressed, I want to check the unlock array and see if it is unlocked. Once the player beats a level, I'll have the GameMaster save it in PlayerPrefs. However, I don't know how to actually save the data in an array using PlayerPrefs. My code for the unlock array is below.
public class GameMaster : MonoBehaviour {
public GameObject pauseMenu;
public GameObject pauseButton;
private int[] LevelUnlocked;
private bool musicOn = false;
public void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void Start()
{
SceneManager.LoadScene("Main");
pauseMenu.SetActive(false);
TogglePauseButton();
//Fill LevelUnlocked array
for (int i = 0; i < 21; i++)
LevelUnlocked[i] = 0;
LevelUnlocked[0] = 1;
//Need to compare to PlayerPrefs to see which should be 1
public void WinLevel()
{
//Need to be able to save in array what level has just been unlocked
}
Then this is where I'm stuck. Any assistance appreciated!
Comment
Your answer
Follow this Question
Related Questions
How can i get the value of the Scrpit what is attached on the Image 0 Answers
PlayerPref doesnt work 2 Answers
PlayerPrefs help ! 1 Answer