Set playerprefs once

I want to set some playerprefs for when the player first plays the game, locking all the levels etc but how can I do this only once and not everytime the player starts the app or presses the play button? what is a good way of doing this? can’t think of any right now.

thanks.

Also to load a level I use this:

		for(int i=0; i < 31; i++){
			int LevelDone = PlayerPrefs.GetInt("LevelC"+i.ToString());
			int j = i+1;
			if(PlayerPrefs.GetInt("LevelC"+i.ToString()) == 2 &&
			   PlayerPrefs.GetInt("LevelC"+j.ToString()) == 1){
				newLevel(i);
}

This works fine in unity editor but once I put it on my phone or any android device it doesnt seem to pick up this code? also how can I set all LevelC’s to 1 but only one time? 1 = not complete 2 = complete but everything has to be not completed at the start.

Make a variable that will be stored in PlayerPrefs itself and use it to check if it is first time or not. Then if it is first time then get PlayerPrefs values and store them otherwise just ignore it.

Something like:

void Start()
{
    // If there is no entry for isFirstTime means it is first time or if there is entry and it is not one means it is first time
    if(!PlayerPrefs.HasKey("isFirstTime") || PlayerPrefs.GetInt("isFirstTime") == 1)
    {
        // Set and save all your PlayerPrefs here.
        // Now set the value of isFirstTime to be false in the PlayerPrefs.
        PlayerPrefs.SetInt("isFirstTime", 1);
        PlayerPrefs.Save();
    }

}