/Scripts/ClimbObject.js
http://acid-and-base.googlecode.com/ · JavaScript · 159 lines · 137 code · 11 blank · 11 comment · 35 complexity · be77bc9e6749494231b95c07bff39822 MD5 · raw file
- //Edited from Pickup script from 3DPlatformer Tutorial
- //Makes Assumptions on how the Acid/Base/Big Red characters are handled
- var sound : AudioClip;
- var soundVolume : float = 2.0;
- var inRangeRed : boolean;
- var inRangeAcid : boolean;
- var inRangeBase : boolean;
- var phInRangeAcid : boolean;
- var phInRangeBase : boolean;
- var top : float;
- var bottom : float;
- var climbable : boolean = true;
- var end : Vector3;
- var bred;
- var acid;
- var base;
- var redclimb : boolean;
- var acidclimb : boolean;
- var baseclimb : boolean;
- function Start ()
- {
- inRangeRed = false;
- inRangeAcid = false;
- inRangeBase = false;
- top = transform.position.y + transform.lossyScale.y - 1;
- bottom = transform.position.y - transform.lossyScale.y;
- end = this.transform.position;
- end.y += this.transform.lossyScale.y + 1;
- bred = GameObject.Find("Big Red");
- acid = GameObject.Find("Acid");
- base = GameObject.Find("Base");
- redclimb = false;
- acidclimb = false;
- baseclimb = false;
- }
- /*
- * Update Changes Acid's or Base's properties depending if they're in range or not
- */
- function Update()
- {
- if(redclimb)
- bred.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
- if(acidclimb)
- acid.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
- if(baseclimb)
- base.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
- var activePlayer = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit).activePlayer;
- if( Input.GetKeyDown(KeyCode.E))
- {
- if(inRangeRed && activePlayer == 0)
- {
- redclimb = true;
- bred.GetComponent("ModifiedController").enabled = false;
- }
- if(phInRangeAcid && activePlayer == 1)
- {
- acidclimb = true;
- acid.GetComponent("ModifiedController").enabled = false;
- }
- if(phInRangeBase && activePlayer == 2)
- {
- baseclimb = true;
- base.GetComponent("ModifiedController").enabled = false;
- }
- }
-
- if(redclimb && bred.transform.position.y >= top)
- {
- bred.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
- bred.transform.position = end;
- redclimb = false;
- bred.GetComponent("ModifiedController").enabled = true;
- }
- if(acidclimb && acid.transform.position.y >= top)
- {
- acid.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
- acid.transform.position = end;
- acidclimb = false;
- acid.GetComponent("ModifiedController").enabled = true;
- }
- if(baseclimb && base.transform.position.y >= top)
- {
- base.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
- base.transform.position = end;
- baseclimb = false;
- base.GetComponent("ModifiedController").enabled = true;
- }
- }
- /*
- * If Acid or Base collides, they are in range.
- */
- function OnTriggerEnter (col : Collider) {
- var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
- var properties : Properties = col.GetComponent(Properties);
- if(cmtr == null)
- return;
- if(properties != null)
- {
- if(properties.abType == AcidOrBase.Acid)
- {
- inRangeAcid = true;
- if (properties.ph >=6){
- phInRangeAcid = true;
- }
- }
- else
- {
- inRangeBase = true;
- if(properties.ph <= 8){
- phInRangeBase = true;
- }
- }
-
- }
- else
- inRangeRed = true;
- }
- /*
- * If Acid or Base leave, they are not in range.
- */
- function OnTriggerExit (col : Collider) {
- var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
- var properties : Properties = col.GetComponent(Properties);
- if(cmtr == null)
- return;
- col.GetComponent("ModifiedController").climbing = false;
- if(properties != null)
- {
- if(properties.abType == AcidOrBase.Acid)
- {
- inRangeAcid = false;
- phInRangeAcid = false;
- }
- else
- {
- inRangeBase = false;
- phInRangeBase = false;
- }
- }
- else
- inRangeRed = false;
- }
- function Reset ()
- {
- if (collider == null)
- gameObject.AddComponent(BoxCollider);
- collider.isTrigger = true;
- }
- @script RequireComponent(BoxCollider)
- @script AddComponentMenu("Third Person Props/ClimbObject")