PageRenderTime 64ms CodeModel.GetById 57ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/ClimbObject.js

http://acid-and-base.googlecode.com/
JavaScript | 159 lines | 137 code | 11 blank | 11 comment | 35 complexity | be77bc9e6749494231b95c07bff39822 MD5 | raw file
  1//Edited from Pickup script from 3DPlatformer Tutorial
  2//Makes Assumptions on how the Acid/Base/Big Red characters are handled
  3
  4var sound : AudioClip;
  5var soundVolume : float = 2.0;
  6var inRangeRed : boolean;
  7var inRangeAcid : boolean;
  8var inRangeBase : boolean;
  9var phInRangeAcid : boolean;
 10var phInRangeBase : boolean;
 11var top : float;
 12var bottom : float;
 13var climbable : boolean = true;
 14var end : Vector3;
 15
 16var bred;
 17var acid;
 18var base;
 19
 20var redclimb : boolean;
 21var acidclimb : boolean;
 22var baseclimb : boolean;
 23function Start ()
 24{
 25	inRangeRed = false;
 26	inRangeAcid = false;
 27	inRangeBase = false;
 28	top = transform.position.y + transform.lossyScale.y - 1;
 29	bottom = transform.position.y - transform.lossyScale.y;
 30	end = this.transform.position;
 31	end.y += this.transform.lossyScale.y + 1;
 32	bred = GameObject.Find("Big Red");
 33	acid = GameObject.Find("Acid");
 34	base = GameObject.Find("Base");
 35	redclimb = false;
 36	acidclimb = false;
 37	baseclimb = false;
 38}
 39
 40/*
 41* Update Changes Acid's or Base's properties depending if they're in range or not
 42*/
 43function Update()
 44{
 45	if(redclimb)
 46		bred.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
 47	if(acidclimb)
 48		acid.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
 49	if(baseclimb)
 50		base.GetComponent(CharacterMotor).SetVelocity(Vector3(0,5,0));
 51
 52	var activePlayer = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit).activePlayer;
 53	if(	Input.GetKeyDown(KeyCode.E))
 54	{
 55		if(inRangeRed && activePlayer == 0)
 56		{
 57			redclimb = true;
 58			bred.GetComponent("ModifiedController").enabled = false;
 59		}
 60		if(phInRangeAcid && activePlayer == 1)
 61		{
 62			acidclimb = true;
 63			acid.GetComponent("ModifiedController").enabled = false;
 64		}
 65		if(phInRangeBase && activePlayer == 2)
 66		{
 67			baseclimb = true;
 68			base.GetComponent("ModifiedController").enabled = false;
 69		}
 70	}
 71	
 72	if(redclimb && bred.transform.position.y >= top)
 73	{
 74		bred.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
 75		bred.transform.position = end;
 76		redclimb = false;
 77		bred.GetComponent("ModifiedController").enabled = true;
 78	}
 79	if(acidclimb && acid.transform.position.y >= top)
 80	{
 81		acid.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
 82		acid.transform.position = end;
 83		acidclimb = false;
 84		acid.GetComponent("ModifiedController").enabled = true;
 85	}
 86	if(baseclimb && base.transform.position.y >= top)
 87	{
 88		base.GetComponent(CharacterMotor).SetVelocity(Vector3(0,0,0));
 89		base.transform.position = end;
 90		baseclimb = false;
 91		base.GetComponent("ModifiedController").enabled = true;
 92	}
 93}
 94
 95/*
 96* If Acid or Base collides, they are in range.
 97*/
 98function OnTriggerEnter (col : Collider) {
 99	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
100	var properties : Properties = col.GetComponent(Properties);
101	if(cmtr == null)
102		return;
103	if(properties != null)
104	{
105			if(properties.abType == AcidOrBase.Acid)
106			{
107				inRangeAcid = true;
108				if (properties.ph >=6){
109					phInRangeAcid = true;
110				}
111			}
112			else
113			{
114				inRangeBase = true;
115				if(properties.ph <= 8){
116					phInRangeBase = true;
117				}
118			}
119			
120	}
121	else
122		inRangeRed = true;
123}
124
125/*
126* If Acid or Base leave, they are not in range.
127*/
128function OnTriggerExit (col : Collider) {
129	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
130	var properties : Properties = col.GetComponent(Properties);
131	if(cmtr == null)
132		return;
133	col.GetComponent("ModifiedController").climbing = false;
134	if(properties != null)
135	{
136			if(properties.abType == AcidOrBase.Acid)
137			{
138				inRangeAcid = false;
139				phInRangeAcid = false;
140			}
141			else
142			{
143				inRangeBase = false;
144				phInRangeBase = false;
145			}
146	}
147	else
148		inRangeRed = false;
149}
150
151function Reset ()
152{
153	if (collider == null)	
154		gameObject.AddComponent(BoxCollider);
155	collider.isTrigger = true;
156}
157
158@script RequireComponent(BoxCollider)
159@script AddComponentMenu("Third Person Props/ClimbObject")