- Home /
Question by
avtar109 · Apr 21, 2015 at 06:17 PM ·
javascripttimeplayerprefs
Help With Quickest TimeScore
I'm trying to save the time in which it took to complete the level and then after that if the beat there time i want it to save that too, i have tried using player prefs but i just carnt figure it out.
Any help would go a long way thank you.
The script im using for the time is below for you to look at if it helps figure out.
var intsec : int; //this variable is to Count in intergurs which basically means counting in whole number such as 1, 2, 3
var minutes = 0; //this variable Counts the minutes
var seconds; //this variable Counts the Seconds
var TimeScore : TextMesh; //Printing the time since level loads
var TimeText = "Time: 0"; //Adding Extra text to the time so that it displays Time:
//Variables for Counting Coins
var PlayerScore : int; //this is a variable that can be incremented by whole numbers to count the coins
var ScoreText = "Coins: 0"; //Adding Extra text to the Coins so that it displays Coins:
public var other : GameObject; //this is so that the coin disappears when it collides with the player
var CoinScore : TextMesh; ////Printing the Coins When Collected
var highscore : int;
var CurrentLvl : int;
function Update() { //Updating continuously
sec = sec + Time.deltaTime; //Counts the seconds since object spawn
intsec = sec; //turns the sec variable from a float which is things like 4.0, 5.0 to an int like 1, 2, 3, 4
if(intsec < 10) //this is saying that if the intsec variable is more than 10 do the statement below
{
seconds = "0"+intsec;
}
else
{
seconds = intsec;
}
if(intsec >= 60)
{
minutes++;
sec=0;
}
TimeText = "Time: " + minutes + ":" + seconds;
{
TimeScore.text = TimeText;
}
{
CurrentLvl = Application.loadedLevel;
PlayerPrefs.SetInt("CurrentLevel", CurrentLvl);
}
{
if (CurrentLvl == 1 && PlayerPrefs.GetInt("CoinTotalLvl1") < PlayerScore) {
PlayerPrefs.SetInt("CoinTotalLvl1", PlayerScore);
}
{
if (CurrentLvl == 1 && PlayerPrefs.GetInt("Lvl1Comp") == 1){
PlayerPrefs.SetInt("MinutesLvl1", minutes);
PlayerPrefs.SetInt("SecondsLvl1", intsec);
}
}
}
}
//Coin Counting and Printing out number
function OnTriggerEnter2D(other : Collider2D){
if (other.tag == "coin"){
PlayerScore +=1;
ScoreText = "Coins: " + PlayerScore;
CoinScore.text = ScoreText;
other.gameObject.active = false;
}
}
Comment
please edit your question with: select all your code and format it as code with the little button which has 0s and 1s on it or with Ctrl+$$anonymous$$. And could you provide more information? what is working and what is not? you can't store the scores or the time? you can't display them? we can help you more if you specify your question :)