How to detect if something is added to PlayerPrefs?

So I have this code on Update()

if (PlayerPrefs.GetInt("Level") == 0) {
	startTime = 14;
	endTime = 131;
}

if (PlayerPrefs.GetInt("Level") == 1) {
	startTime = 13;
	endTime = 130;
}
if (PlayerPrefs.GetInt("Level") == 2) {
	startTime = 12;
	endTime = 60;
}

It keeps going till level 12 and this really affects performance. It droppes fps from 5000 to 15. How can I detect if 1 is added to PlayerPrefs?

You can’t detect when something is added, however, you could create an event, subscribe to that event with an appropriate delegate that is invoked when setting the int for level.

Check out the Event Tutorial, it might have to do with mouse clicking, but you really just need to apply it to your structure, when the level int is set and saved for PlayerPrefs.

Here you can see where the playerprefs data is stored on the disk. Please note, that the datas will be on the disk if the application terminates successfully or you call PlayerPrefs.Save().

So if your program is running and you didnt call Save function the datas are stored in the memory not on the disk