• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PlayerPref doesnt work 2 Answers

PlayerPrefs help ! 1 Answer

Saving In Between Scenes and Program Exit 0 Answers

Does anyone know how to make a level select map just like mario bros 3 own? 0 Answers

PlayerPrefs not saving specific values 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges