Adding items to the berg Zerg arcade inventory and saving

Hello I followed the burg Zerg arcade RPG tutorials and I want to save the inventory like in players prefs and also add items when a quest is completed so please help. Thanks

1 Answer

1

Look into playerPrefs.

You can define a new variable anywhere in your code like this using a pre-existing variable in your game.

int playerXP;

Update()
{
//stuff happens which causes player to gain playerXP
++playerXP

//this creates a new player Pref variable called "Player XP", it uses your playerXP int variable to set it's value.
//whenever you gain XP you can also set it to your playerPrefs in this way.
PlayerPrefs.SetInt("Player XP", playerXP);


}

//then when you start the game to retrieve XP from previous session you can go:

Start()
{

//retrieving "Player XP" with a default value of 0
// if you never set this PlayerPref like the above Update() example it will be 0. But you can change to whatever you want.
PlayerPrefs.GetInt("Player XP", 0);

}

So you can define, save and retrieve countless PlayerPrefs for all your saving needs with the above method.

Look into the documentation for more specifics.

Oh also you can set your pre-existing variables to a playerPref. so: playerXP = PlayerPrefs.GetInt("Player XP", 0);

–