-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoringSystem.js
More file actions
85 lines (70 loc) · 1.65 KB
/
Copy pathScoringSystem.js
File metadata and controls
85 lines (70 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import UnityEngine.UI;
import System.IO;
static var filenameIOS = "/Documents/highscore.data";
static var filenamereg = "highscore.data";
static var filename: String;
static var Score : int;
static var highScore : String;
var textToChange : GameObject;
var sphere : GameObject;
var newForce : Vector3;
static var i : int;
static var go : boolean;
static var newHighScore;
var line : String;
function Start () {
Score = 0;
i = 0;
go = false;
newHighScore = false;
var x = textToChange.GetComponent(UI.Text);
try {
if (Application.platform == RuntimePlatform.IPhonePlayer) {
filename = Application.persistentDataPath + "/" + filenamereg;
} else {
filename = filenamereg;
}
var sr : StreamReader = new StreamReader(filename);
line = sr.ReadLine();
while (line != null) {
highScore = line;
line = sr.ReadLine();
}
sr.Close();
} catch (err) {
highScore = "0";
}
newForce = Vector3(0,0,.05);
x.text = "High Score: " + highScore;
}
function goAhead () {
go = true;
}
static function stopAndSave() {
go = false;
if (Score > parseInt(highScore)) {
var newFile = File.CreateText(filename);
newFile.WriteLine(Score);
newFile.Close();
newHighScore = true;
}
}
static function incScore() {
i++;
}
function Update () {
if (go) {
var x = textToChange.GetComponent(UI.Text);
x.text = Score.ToString();
var y = Time.time + i;
Score = y;
if (Score > 19) {
sphere.GetComponent(ConstantForce).enabled = false;
sphere.GetComponent(ConstantForce).force = newForce;
sphere.GetComponent(ConstantForce).enabled = true;
}
if (Score > int.Parse(highScore)) {
x.text = "New HighScore! " + Score.ToString();
}
}
}