Hey guys, my project is coming to an end now and during bug testing I found a little error when testing on different machines. First of all, when I run it on my personal machine and I finish my level, it displays a working high score system that displays my highest score (Please note even if I shut my machine down and wait a week, this will still be saved). The problem is, when testing on my laptop, the high scores do not record :O!!! I can fix it by recompiling the script (to be exact I chance > to < and then back to > and click save and it works. I can only presume it is creating a file. Has anyone encountered this at all? Here are my two scripts that I used for the system:
NUMBER 1 :
var myStyle : GUIStyle; // GUI style for the static variable below
static var myTimer : float; // Static variable that displays a timer. This is used in multiple scripts
// Sets the timer to 0 on startup.
function Start()
{
myTimer = 0;
}
// The timer will increase by 1 every second, providing targets are still active.
function Update () {
if(CollisionChicken.chickenHit>=1)
{
//Debug.Log ("We got inside!");
myTimer += Time.deltaTime;
}
// If the targets are destroyed, load the end game screen. Additionally, write to the string "fastestTime" so we can record a highscore. PLEASE NOTE: THIS MAY NEED TO BE RECOMPILED IN ORDER TO
// WORK CORRECTLY. IF SO, CHANGE THE < TO > AND THEN BACK AND IT WILL WORK ONCE RE-COMPILED.
if (CollisionChicken.chickenHit<=0) {
if (myTimer < PlayerPrefs.GetInt("fastestTime")){
PlayerPrefs.SetInt("fastestTime", myTimer);
}
Application.LoadLevel(2);
Hull.hull = 100;
Fuel.fuel = 100;
CollisionChicken.chickenHit = 3;
}
}
// Prints the timer variable to 1 decimal place.
function OnGUI()
{
GUI.Label( Rect(250, 10, 100, 20), myTimer.ToString("f0"), myStyle );
}
// this is where the data is recorded. SCRIPT NAME : countdown.js
NUMBER 2:
var hScore: TextMesh; //Declares a text mesh
// Print the saved data from the Countdown script after the string "High Score: ". After this has been printed, add " Seconds".
// High Score: 10 Seconds
function Awake(){
hScore.text = "High Score: " + PlayerPrefs.GetInt("fastestTime") + " Seconds";
}
//Displays highscore on gameover screen. SCRIPT NAME : highscoredisplay.js
As mentioned above this works fine until I use another machine. To get it working on another machine I need to recompile the script. Has anyone bumped into this before? Any help is appreciated, this has baffled me