Fanzhong Zeng

There are two simple methods of writing scripts for the mouse to interact with the game object. A simple method is to write a script for each game object where on mouse down or up, execute some code. However, you can also have a raycast to spawn at where the…

This is just a simple guide for saving and loading data from PlayerPrefs in Unity.

PlayerPrefs system in Unity allows users to store and access player data between game sessions. It stores data in a plain text file which makes any data easy to access but also easy to hack. Therefore try not to store any important data in PlayerPrefs.

Before starting, note that PlayerPrefs allows users to store 3 different types of data:

  • SetFloat()
  • SetInt()
  • SetString()

First I create an empty game object in Unity and call it GameController, while giving it the tag GameController as well. Then I create a new C# script where I’m going to edit and read data from, called PrefsControl.

You can easily access these functions from any other script, just find the game object first, then find the script and access it from there.