/Scripts/InteractAlert.js

http://acid-and-base.googlecode.com/ · JavaScript · 144 lines · 129 code · 9 blank · 6 comment · 37 complexity · 170e428caad2a31244f8720f392c4ce1 MD5 · raw file

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