-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTentacleFlailRandom.js
36 lines (30 loc) · 1.07 KB
/
TentacleFlailRandom.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
#pragma strict
var mainAnimation : String;
var triggerAnimation1 : String;
var triggerAnimation2 : String;
var triggerInTime : float = 0.5;
var triggerOutTime : float = 1.0;
private var audioSource: AudioSource;
private var thisAnimation: Animation;
function Start() {
audioSource = GetComponent.<AudioSource>();
thisAnimation = GetComponent.<Animation>();
}
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("Player")) {
var seconds : int = Time.time;
//var oddeven = (seconds % 2) == 0; // Find out whether current second is odd or even
var oddeven : int = Random.Range(0, 2);
var animationToRun : String;
// Debug.Log("oddeven was " + oddeven);
animationToRun = (oddeven == 0) ? triggerAnimation1 : triggerAnimation2 ;
thisAnimation.CrossFade(animationToRun, triggerInTime);
if (audioSource) {audioSource.Play();}
}
}
function OnTriggerExit (other : Collider) {
if (other.gameObject.CompareTag ("Player")) {
//thisAnimation.PlayQueued("twist2", QueueMode.PlayNow);
thisAnimation.CrossFade(mainAnimation, triggerOutTime);
}
}