-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pulser.js
58 lines (48 loc) · 1.07 KB
/
Pulser.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
#pragma strict
var duration = 1.0;
var scales = Vector3(2,2,2);
var fontSizeMax = 30;
var looping = false;
var playOnAwake = false;
private var startTime:float = 0.0;
private var startScale:Vector3;
private var startFontSize:float;
private var state:String;
function Start () {
}
function Awake() {
state = "stopped";
if( playOnAwake )
Play();
}
function Play() {
startScale = transform.localScale;
startTime = Time.time;
state = "playing";
if( GetComponent(GUIText) ) {
startFontSize = GetComponent(GUIText).fontSize;
}
}
function Stop() {
transform.localScale = startScale;
state = "stopped";
}
function Update () {
if( state == "playing" ) {
var frac = (Time.time-startTime) / duration;
if( frac > 1.0 ) {
if( looping ) {
frac = frac % 1.0;
}
else {
Stop();
}
}
var lerpVal = Mathf.Sin(Mathf.PI*frac);
if( GetComponent(GUIText) ) {
GetComponent(GUIText).fontSize = (1-lerpVal)*startFontSize + lerpVal*fontSizeMax;
}
else
transform.localScale = Vector3.Scale( startScale, Vector3.Lerp(Vector3(1,1,1), scales, lerpVal) );
}
}