-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevelGUI.js
86 lines (67 loc) · 1.83 KB
/
LevelGUI.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
75
76
77
78
79
80
81
82
83
84
85
86
#pragma strict
var origFixedDeltaTime : float;
var origTimeScale : float;
var inSloMo : boolean = false;
var start : float;
var end : float;
var physStart : float;
var physEnd : float;
var SlomoFactor : float = .25;
function Start () {
origFixedDeltaTime = Time.fixedDeltaTime;
origTimeScale = Time.timeScale;
}
function OnGUI()
{
if(GUI.Button (Rect (20,(Screen.height - 80),100,60),"Restart"))
{
Application.LoadLevel(Application.loadedLevel);
}
if(GUI.Button (Rect ((Screen.width/2),(Screen.height - 80),100,60),"Skip"))
{
transform.position.x = 17600;
}
if(GUI.Button (Rect ((Screen.width - 120),(Screen.height - 80),100,60),"Slomo"))
{
if (inSloMo) {EndSloMo();}
else {BeginSloMo();}
}
}
function BeginSloMo () {
// Time.timeScale = .25 * Time.timeScale;
// Time.fixedDeltaTime = origFixedDeltaTime * 4;
LerpTime(true, 0.75);
inSloMo = true;
}
function EndSloMo () {
// Time.timeScale = origTimeScale;
// Time.fixedDeltaTime = origFixedDeltaTime;
LerpTime(false, .5);
inSloMo = false;
}
function LerpTime (slowing : boolean, timer : float) {
if (slowing) {
start = origTimeScale;
end = SlomoFactor * origTimeScale;
physStart = origFixedDeltaTime;
physEnd = (origFixedDeltaTime * SlomoFactor);
}
else {
start = SlomoFactor * origTimeScale;
end = origTimeScale;
physStart = (origFixedDeltaTime * SlomoFactor);
physEnd = origFixedDeltaTime;
}
var i = 0.0;
var step = 1.0/timer;
while (i <= 1.0) {
i += step * Time.deltaTime;
Time.timeScale = Mathf.Lerp(start, end, i);
Time.fixedDeltaTime = Mathf.Lerp(physStart, physEnd, i);
#if UNITY_EDITOR
Debug.Log("my timescale is " + Time.timeScale);
#endif
yield;
}
yield WaitForSeconds (timer);
}