/Scripts/ThoughtBubble.js

http://acid-and-base.googlecode.com/ · JavaScript · 97 lines · 80 code · 10 blank · 7 comment · 21 complexity · ab04321e4c9e6586df9dc646db4857ab MD5 · raw file

  1. var inRangeA:boolean;
  2. var inRangeB:boolean;
  3. var inRangeR:boolean;
  4. var thoughtText:String;
  5. var custom:GUIStyle;
  6. var defaultstyle:GUIStyle;
  7. enum CharacterThought { Red=0, Acid=1, Base=2 }
  8. var focusedCharacter : CharacterThought;
  9. var showA:boolean;
  10. var showB:boolean;
  11. var showR:boolean;
  12. function Start()
  13. {
  14. inRangeA = false;
  15. inRangeB = false;
  16. inRangeR = false;
  17. showA = false;
  18. showB = false;
  19. showR = false;
  20. }
  21. function OnGUI ()
  22. {
  23. //Show the contents of the menu if it is active
  24. switch (focusedCharacter)
  25. {
  26. case CharacterThought.Red:
  27. if(showR)
  28. {
  29. // Make a background box
  30. GUI.Box (Rect ((Screen.width-400)/2,(Screen.height-400)/2,400,400), "",custom);
  31. GUI.Label (Rect ((Screen.width-200)/2,(Screen.height)/2,400,200), thoughtText,defaultstyle);
  32. }
  33. break;
  34. case CharacterThought.Acid:
  35. if(showA)
  36. {
  37. // Make a background box
  38. GUI.Box (Rect ((Screen.width-400)/2,(Screen.height-400)/2,400,400), "",custom);
  39. GUI.Label (Rect ((Screen.width-200)/2,(Screen.height)/2,400,200), thoughtText,defaultstyle);
  40. }
  41. break;
  42. case CharacterThought.Base:
  43. if(showB)
  44. {
  45. // Make a background box
  46. GUI.Box (Rect ((Screen.width-400)/2,(Screen.height-400)/2,400,400), "",custom);
  47. GUI.Label (Rect ((Screen.width-200)/2,(Screen.height)/2,400,200), thoughtText,defaultstyle); }
  48. break;
  49. }
  50. }
  51. function OnTriggerEnter (col : Collider) {
  52. var property : Properties = col.GetComponent(Properties);
  53. if(property == null)
  54. return;
  55. if(property.abType == AcidOrBase.Base)
  56. inRangeB = true;
  57. else
  58. inRangeA = true;
  59. }
  60. /*
  61. * If Acid or Base leave, they are not in range.
  62. */
  63. function OnTriggerExit (col : Collider) {
  64. var property : Properties = col.GetComponent(Properties);
  65. if(property == null)
  66. return;
  67. if(property.abType == AcidOrBase.Base)
  68. inRangeB = false;
  69. else
  70. inRangeA = false;
  71. }
  72. function Update ()
  73. {
  74. var mcontrol = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit);
  75. if(mcontrol.getActivePlayer() == 0 && inRangeR)
  76. showR = true;
  77. else
  78. showR = false;
  79. if(mcontrol.getActivePlayer() == 1 && inRangeA)
  80. showA = true;
  81. else
  82. showA = false;
  83. if(mcontrol.getActivePlayer() == 2 && inRangeB)
  84. showB = true;
  85. else
  86. showB = false;
  87. }