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