- Home /
Problem with the Playerprefs
Hi I make a game and now I want to add a score but it doesn't work with the Playerprefs Everytime when I write this it says GetInt is not a member of Playerprefs.
var score : int = 0;
var scoreText : GUIText;
function Start(){
score = PlayerPrefs.GetInt("Score");
}
function Update() {
scoreText.text = "Score: " + score;
}
Assets/Scripts/PlayerPrefs.js(7,25): BCE0019: 'GetInt' is not a member of 'PlayerPrefs'.
i pasted your code without any problems/errors. is the code posted here the complete file?
EDIT: Doh!! can't believe i didn't spot it sooner.
change the filename from PlayerPrefs.js to something else. you're overriding Unity's own PlayerPrefs methods...
Here is the score script function Start(){ InvokeRepeating("EachSecond",1.0,1.0); }
var score: float = 0;
var addscore = 1;
var score1 : GUIText;
function EachSecond()
{
score=score+addscore;
}
function Update()
{
score1.text = "Score: " + score;
}
function GameOver(){
PlayerPrefs.SetInt("Score", score);
}
there are now no erros anymore but everytime when play the game and I die it say "Score: 0"and not my score Please Help!!
Answer by ironblock · Jul 28, 2014 at 03:00 PM
this is what i use to get my score (its in c# tho) :
using UnityEngine;
using System.Collections;
public class GetHighScore : MonoBehaviour {
public TextMesh highScoreText ;
public GUIText highScoreGuiText ;
private int score;
private string setScore;
public bool GuiScore = false;
// Use this for initialization
void Awake () {
score = PlayerPrefs.GetInt ("highScore");
setScore = score.ToString("f0");
if (GuiScore == false)
{
highScoreText.GetComponent<TextMesh> ().text = "personal best : " + setScore + " points";
}
if (GuiScore == true)
{
highScoreGuiText.GetComponent<GUIText> ().text = setScore + " points";
}
}
}
and this is what i use to set it :
if (newScoreI > PlayerPrefs.GetInt("highScore"))
{
PlayerPrefs.SetInt("highScore",(newScoreI ));
}
Your answer
Follow this Question
Related Questions
Playerprefs not work!? 0 Answers
Loading a scene and keeping original score 3 Answers
Where am I going wrong with these scripts? 1 Answer