-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScoreControllerOnGui.js
74 lines (55 loc) · 1.73 KB
/
ScoreControllerOnGui.js
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
var customscore : GUIStyle;
var myscore = visibleScore.ToString();
// Keep track of the players main score
static var currentScore : int = 10;
static var startingScore = 10f;
// Keep track of the currently visible score
var visibleScore : int = 10;
var native_width : float = 960;
var native_height : float = 640;
// Draw the score to the screen using Unity's GUI methods
function OnGUI () {
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
GUILayout.BeginArea ( Rect ( 40, 40, 120, 120 ) );
// GUILayout.BeginArea ( Rect ( 20, 20, Screen.width / 4, Screen.height / 4 ) );
GUILayout.Box ( visibleScore.ToString (), customscore);
GUILayout.EndArea ();
}
// Animate score changes using iTween's ValueTo
function AnimateVisibleScore () {
iTween.ValueTo ( gameObject,
{
"from" : visibleScore,
"to" : currentScore,
"onupdate" : "ChangeVisibleScore",
"time" : 0.2
}
);
}
// Change the currently visible score. Called every time iTween changes my
// visibleScore variable
function ChangeVisibleScore ( i : int ) {
visibleScore = i;
}
// Increment Score
function IncrementScore ( i : int ) {
currentScore += i;
AnimateVisibleScore ();
}
// Decrement Score
function DecrementScore ( i : int ) {
currentScore -= i;
AnimateVisibleScore ();
}
function ZeroScore ( i : int ) {
currentScore = 0;
// currentScore = (currentScore - visibleScore);
AnimateVisibleScore ();
}
function ResetScore ( i : int ) {
currentScore = 10;
// currentScore = (currentScore - visibleScore);
AnimateVisibleScore ();
}