/Scripts/AntRide.js
http://acid-and-base.googlecode.com/ · JavaScript · 62 lines · 47 code · 15 blank · 0 comment · 9 complexity · 9d9c9cfe661bc64cdabcfe9001e592a5 MD5 · raw file
- var inRange = false;
- var carried = false;
- function Update()
- {
- var ant = gameObject.Find("Happy Ant");
- var bred = gameObject.Find("Big Red");
-
- if(Input.GetKeyDown(KeyCode.E) && inRange){ // Hop on the ant
- Debug.Log("In range and E hit!");
-
- bred.GetComponent(CharacterMotor).enabled = false; // disable movement
- ant.GetComponent(Animation).enabled = true;
- ant.GetComponent(Animation).wrapMode = WrapMode.Once;
- ant.GetComponent(Animation).Play();
-
- carried = true;
- }
-
- if(carried){
- bred.GetComponent(Transform).rotation = gameObject.Find("Ant").GetComponent(Transform).rotation;
- bred.GetComponent(Transform).position = gameObject.Find("Happy Ant").GetComponent(Transform).position;
- bred.GetComponent(Transform).position.y += 1; // place big red on top of the ant
- }
-
- if(!ant.GetComponent(Animation).isPlaying){ // ant ride is over
- bred.GetComponent(CharacterMotor).enabled = true;
- ant.GetComponent(Animation).Rewind();
- ant.GetComponent(Animation).enabled = false;
-
- carried = false;
- }
-
- if(carried && Input.GetKeyDown(KeyCode.V)){ // Get off the Ant
- bred.GetComponent(CharacterMotor).enabled = true;
- ant.GetComponent(Animation).Rewind();
- ant.GetComponent(Animation).enabled = false;
-
- carried = false;
- }
- }
- function Reset ()
- {
- if (collider == null)
- gameObject.AddComponent(MeshCollider);
- collider.isTrigger = true;
- }
- function OnTriggerEnter(col : Collider) {
- if(col.GetComponent(CharacterController)){
- Debug.Log("Ant hit!");
- inRange = true;
-
- }
- }
- function OnTriggerExit(col : Collider){
- inRange = false;
- }