- Home /
Question by
Zypher · Jun 14, 2014 at 12:18 AM ·
playerprefsscore system
Detailed Help on using PlayerPrefs?
I simply cannot get this. I'm trying to save the player's score and while also trying to display it on the game over scene. Could I get detailed instructions on how playerprefs work and how I can insert them into my game.
Here is my player script:
#pragma strict
static var currentScore : int = 0;
var offsetY : float = 40;
var sizeX : float = 200;
var sizeY : float = 20;
function Awake()
{
currentScore = 0;
}
function OnGUI () {
GUI.color = Color.yellow;
GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "" + currentScore);
}
GameMaster.currentScore += 1;
This is the whole thing hindering the publishing of my game.
Comment
Best Answer
Answer by iwaldrop · Jun 14, 2014 at 03:52 AM
PlayerPrefs simply stores values by key on the device that the game is running on.
See the documentation for an overview.
In short, however, here is how you'd save an int.
public class SomeClass : MonoBehaviour
{
const string PPKEY_EXAMPLE_KEY_NAME = "SomeInt"
void Awake()
{
someInt = PlayerPrefs.GetInt(PPKEY_EXAMPLE_KEY_NAME, 0);
}
public int SomeInt
{
get
{
return someInt;
}
set
{
someInt = value;
PlayerPrefs.SetInt(PPKEY_EXAMPLE_KEY_NAME, someInt);
}
}
private int someInt;
}
Your answer
Follow this Question
Related Questions
How do you transfer UI Text from one scene to another? 1 Answer
Save score in Unity 1 Answer
Highscore won't save 3 Answers