PageRenderTime 22ms CodeModel.GetById 9ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/InteractAlert.js

http://acid-and-base.googlecode.com/
JavaScript | 144 lines | 129 code | 9 blank | 6 comment | 37 complexity | 170e428caad2a31244f8720f392c4ce1 MD5 | raw file
  1var inRangeBase : boolean;
  2var inRangeAcid : boolean;
  3var inRangeRed : boolean;
  4
  5var showRed : boolean;
  6var showAcid : boolean;
  7var showBase : boolean;
  8var markgraphic : GameObject;
  9private var clone;
 10
 11function Start ()
 12{
 13	inRangeBase = false;
 14	inRangeAcid = false;
 15	inRangeRed = false;
 16	showRed = false;
 17	showAcid = false;
 18	showBase = false;
 19	emark = null;
 20}
 21
 22function Update () 
 23{
 24	var bred = GameObject.Find("Big Red");
 25	var acid = GameObject.Find("Acid");
 26	var base = GameObject.Find("Base");
 27	var activePlayer = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit).activePlayer;
 28	if(inRangeRed && activePlayer == 0)
 29		showRed = true;
 30	else
 31		showRed = false;
 32	if(inRangeAcid && activePlayer == 1)
 33		showAcid = true;
 34	else
 35		showAcid = false;
 36	if(inRangeBase && activePlayer == 2)
 37		showBase = true;
 38	else
 39		showBase = false;
 40	if(clone == null)
 41	{
 42		if(showRed)
 43		{
 44			clone = Instantiate(markgraphic, bred.transform.position, Quaternion(0,0,0,0));
 45		}
 46		else if(showAcid)
 47		{
 48			clone = Instantiate(markgraphic, acid.transform.position, Quaternion(0,0,0,0));
 49		}
 50		else if(showBase)
 51		{
 52			clone = Instantiate(markgraphic, base.transform.position, Quaternion(0,0,0,0));
 53		}
 54	}
 55	else
 56	{
 57		if(showRed)
 58		{
 59			clone.transform.position = bred.transform.position;
 60			clone.transform.position.y += 1;
 61		}
 62		else if(showAcid)
 63		{
 64			clone.transform.position = acid.transform.position;
 65			clone.transform.position.y += 1.25;
 66		}
 67		else if(showBase)
 68		{
 69			clone.transform.position = base.transform.position;
 70			clone.transform.position.y += 1;
 71		}
 72		else
 73		{
 74			Destroy(clone);
 75			clone = null;
 76		}
 77	}
 78		
 79}
 80
 81/*
 82* If Acid or Base collides, they are in range.
 83*/
 84function OnTriggerEnter (col : Collider) {
 85	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
 86	var properties : Properties = col.GetComponent(Properties);
 87	if(cmtr == null)
 88		return;
 89	if(properties != null)
 90	{
 91			if(properties.abType == AcidOrBase.Acid)
 92			{
 93				inRangeAcid = true;
 94				if (properties.ph >=6){
 95					phInRangeAcid = true;
 96				}
 97			}
 98			else
 99			{
100				inRangeBase = true;
101				if(properties.ph <= 8){
102					phInRangeBase = true;
103				}
104			}
105			
106	}
107	else
108		inRangeRed = true;
109}
110
111/*
112* If Acid or Base leave, they are not in range.
113*/
114function OnTriggerExit (col : Collider) {
115	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
116	var properties : Properties = col.GetComponent(Properties);
117	if(cmtr == null)
118		return;
119	if(properties != null)
120	{
121			if(properties.abType == AcidOrBase.Acid)
122			{
123				inRangeAcid = false;
124				phInRangeAcid = false;
125			}
126			else
127			{
128				inRangeBase = false;
129				phInRangeBase = false;
130			}
131	}
132	else
133		inRangeRed = false;
134}
135
136function Reset ()
137{
138	if (collider == null)	
139		gameObject.AddComponent(SphereCollider);
140	collider.isTrigger = true;
141}
142
143@script RequireComponent(SphereCollider)
144@script AddComponentMenu("Third Person Props/InteractAlert")