PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/AntRide.js

http://acid-and-base.googlecode.com/
JavaScript | 62 lines | 47 code | 15 blank | 0 comment | 9 complexity | 9d9c9cfe661bc64cdabcfe9001e592a5 MD5 | raw file
 1var inRange = false;
 2var carried = false;
 3
 4function Update()
 5{
 6	var ant = gameObject.Find("Happy Ant");
 7	 var bred = gameObject.Find("Big Red");
 8    
 9	if(Input.GetKeyDown(KeyCode.E) && inRange){ // Hop on the ant
10		Debug.Log("In range and E hit!");
11		
12		bred.GetComponent(CharacterMotor).enabled = false; // disable movement
13		ant.GetComponent(Animation).enabled = true;
14		ant.GetComponent(Animation).wrapMode = WrapMode.Once;
15		ant.GetComponent(Animation).Play();
16		
17		carried = true;
18	}
19	
20	if(carried){
21    bred.GetComponent(Transform).rotation = gameObject.Find("Ant").GetComponent(Transform).rotation;
22		bred.GetComponent(Transform).position = gameObject.Find("Happy Ant").GetComponent(Transform).position;
23		bred.GetComponent(Transform).position.y += 1; // place big red on top of the ant
24	}
25	
26	if(!ant.GetComponent(Animation).isPlaying){ // ant ride is over
27		bred.GetComponent(CharacterMotor).enabled = true;
28		ant.GetComponent(Animation).Rewind();
29		ant.GetComponent(Animation).enabled = false;
30		
31		carried = false;
32	}
33	
34	if(carried && Input.GetKeyDown(KeyCode.V)){ // Get off the Ant
35		 bred.GetComponent(CharacterMotor).enabled = true;	
36		 ant.GetComponent(Animation).Rewind();
37		 ant.GetComponent(Animation).enabled = false;
38		
39		 carried = false;			
40	}
41}
42
43function Reset ()
44{
45        if (collider == null)
46                gameObject.AddComponent(MeshCollider);
47        collider.isTrigger = true;
48}
49
50function OnTriggerEnter(col : Collider) {
51	if(col.GetComponent(CharacterController)){
52		Debug.Log("Ant hit!");
53		inRange = true;
54		
55	}
56}
57
58function OnTriggerExit(col : Collider){
59	inRange = false;	
60}
61
62