How to use PlayerPrefs to activate game objects permanently?

Hello fam,

I am trying to create a simple trophy system within my game. I’ve managed to use PlayerPrefs to store data such as Integers for recording high scores etc. but I can’t seem to figure out how to easily implement PlayerPrefs for activating a trophy game object. Can someone please give me a play by play on how to achieve this? I’m using C#. Thank you so much for anyone reading this.

All you have to do is assign a “key” to each trophy game object. For example, if you have a trophy called “Winner”, you can simply assign it in PlayerPrefs:

PlayerPrefs.SetInt("winnerTrophy", 1);

Since PlayerPrefs doesn’t have booleans, we can use the integers 1 and 0 to represent true and false respectively. The integer is arbitrary; we only need the key to be stored in PlayerPrefs to check for trophies (i.e. only store trophies that have been activated in playerprefs).

Next, you would keep a list of trophies in either a ScriptableObject or a Monobehaviour Class with their key names. Thereafter, you would just use a simple for loop when the game starts:

for (int i = 0; i < trophiesList.Length; i++) {
    if (PlayerPrefs.HasKey(trophiesList*)) {*

// Trophy is activated, you can do other things here
}
}