/Scripts/InteractAlert.js
http://acid-and-base.googlecode.com/ · JavaScript · 144 lines · 129 code · 9 blank · 6 comment · 37 complexity · 170e428caad2a31244f8720f392c4ce1 MD5 · raw file
- var inRangeBase : boolean;
- var inRangeAcid : boolean;
- var inRangeRed : boolean;
- var showRed : boolean;
- var showAcid : boolean;
- var showBase : boolean;
- var markgraphic : GameObject;
- private var clone;
- function Start ()
- {
- inRangeBase = false;
- inRangeAcid = false;
- inRangeRed = false;
- showRed = false;
- showAcid = false;
- showBase = false;
- emark = null;
- }
- function Update ()
- {
- var bred = GameObject.Find("Big Red");
- var acid = GameObject.Find("Acid");
- var base = GameObject.Find("Base");
- var activePlayer = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit).activePlayer;
- if(inRangeRed && activePlayer == 0)
- showRed = true;
- else
- showRed = false;
- if(inRangeAcid && activePlayer == 1)
- showAcid = true;
- else
- showAcid = false;
- if(inRangeBase && activePlayer == 2)
- showBase = true;
- else
- showBase = false;
- if(clone == null)
- {
- if(showRed)
- {
- clone = Instantiate(markgraphic, bred.transform.position, Quaternion(0,0,0,0));
- }
- else if(showAcid)
- {
- clone = Instantiate(markgraphic, acid.transform.position, Quaternion(0,0,0,0));
- }
- else if(showBase)
- {
- clone = Instantiate(markgraphic, base.transform.position, Quaternion(0,0,0,0));
- }
- }
- else
- {
- if(showRed)
- {
- clone.transform.position = bred.transform.position;
- clone.transform.position.y += 1;
- }
- else if(showAcid)
- {
- clone.transform.position = acid.transform.position;
- clone.transform.position.y += 1.25;
- }
- else if(showBase)
- {
- clone.transform.position = base.transform.position;
- clone.transform.position.y += 1;
- }
- else
- {
- Destroy(clone);
- clone = null;
- }
- }
-
- }
- /*
- * 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;
- 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(SphereCollider);
- collider.isTrigger = true;
- }
- @script RequireComponent(SphereCollider)
- @script AddComponentMenu("Third Person Props/InteractAlert")