- Home /
I am trying to create a script that saves score i have tried using playprefs but i am not to familiar on them to know just how to use them
var Obj : Transform;
var ObjScript : TimeTaken = Obj.GetComponent("TimeTaken");
var BestTimeMin = 0;
var BestTimeSec = 0;
var BestCoin : int;
var Level1Coin : int;
var Level1Time = "Time: 0";
public var ScoreSaver : GameObject;
var LvlCompObj : Transform;
var LvlComp : LevelComplete = LvlCompObj.GetComponent("Boolan");
//this is so that the object scorescript doesnt get destroyed
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
//this calls the time in minutes and seconds and also calls the amount of coins collected
function Update () {
BestCoin = ObjScript.PlayerScore;
BestTimeMin = ObjScript.minutes;
BestTimeSec = ObjScript.seconds;
}
//this is for saving the score
function OnTriggerEnter2D (ScoreSaver : Collider2D) {
if (ScoreSaver.tag == "LevelEnd") {
Level1Coin = BestCoin;
Level1Time = "Time: " + BestTimeMin + ":" + BestTimeSec;
}
}
Answer by Veldars · Apr 08, 2015 at 05:17 PM
I think you need to read the documentation : http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html
To save a score simply do : PlayerPrefs.SetInt("Score", myScore);
and to load it : PlayerPrefs.LoadInt("Score");
You can do the same with String and Float
Your answer
![](https://koobas.hobune.stream/wayback/20220613192521im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help With Quickest TimeScore 0 Answers
Time.deltaTime not consistent over time 1 Answer
Breathing sound effect using timers 1 Answer
Updating an array indices dynamically 2 Answers
Comparing Time 1 Answer