Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class InGameVis : MonoBehaviour {
  5.  
  6. GameObject courseObject;
  7. Course4 courseScript;
  8.  
  9. float width; float height;
  10. public bool ready = false;
  11.  
  12. string toMove = "Move left and right with '" + Player4.leftKey
  13. + "' & '" + Player4.rightKey + "'";
  14. string toJump = "\nJump with " + Player4.jumpKey + "bar";
  15. string toPlatform = "\nActivate platform for next jump with '" + Player4.upPlatformKey + "'";
  16. string toDrop = "\nDestroy a block you're standing on with '" + Player4.dropKey + "'";
  17. string instrText;
  18.  
  19. string scoreText = "Blocks used: ";
  20. int scoreVal = 0;
  21. string prevScoreText = "Fewest blocks used so far: ";
  22. int prevScoreVal = 10000;
  23.  
  24. bool muted = false;
  25.  
  26.  
  27. void Start() {
  28.  
  29. // DontDestroyOnLoad( gameObject );
  30.  
  31. PlayerPrefs.SetInt("prevScoreVal", 10000);
  32.  
  33. courseObject = GameObject.Find("buildCourse");
  34. courseScript = (Course4) courseObject.GetComponent("Course4");
  35.  
  36. width = Screen.width - 50;
  37. height = Screen.height - 75;
  38.  
  39. scoreVal = courseScript.score;
  40.  
  41. instrText = toMove + toJump + toPlatform + toDrop;
  42.  
  43. ready = true;
  44. // This logs as True
  45. Debug.Log("[InGameVis] OnGUI(): ready " + ready);
  46.  
  47.  
  48.  
  49. }
  50. //
  51.  
  52.  
  53. public void StartGameGUI () {
  54.  
  55.  
  56. // courseObject = GameObject.Find("buildCourse");
  57. // courseScript = (Course4) courseObject.GetComponent("Course4");
  58. //
  59. // width = Screen.width - 50;
  60. // height = Screen.height - 75;
  61. //
  62. // scoreVal = courseScript.score;
  63. //
  64. // instrText = toMove + toJump + toPlatform + toDrop;
  65. //
  66. // ready = true;
  67. // // This logs as True
  68. // Debug.Log("[InGameVis] OnGUI(): ready " + ready);
  69.  
  70. }
  71.  
  72.  
  73. void OnGUI () {
  74. // This always logs as False
  75. Debug.Log("[InGameVis] OnGUI(): ready " + ready);
  76. if ( ready ) {
  77. // INSTRUCTIONS
  78. GUI.Label( new Rect(10, 5, 1000, 300), instrText );
  79.  
  80. // BUTTONS
  81. // xCoord = screenWidth - (width + margin)
  82. if ( GUI.Button(new Rect(470,10,70,20),"Restart") ){
  83.  
  84. Goal.resetWon();
  85. if ( PlayerPrefs.GetInt("prevScoreVal") > scoreVal ) {
  86. PlayerPrefs.SetInt("prevScoreVal", scoreVal);
  87. }
  88.  
  89. Application.LoadLevel(Application.loadedLevel);
  90.  
  91. muted = false;
  92. }
  93.  
  94. if ( !muted ) {
  95. // xCoord = screenWidth - (width + margin)
  96. if ( GUI.Button(new Rect(470,35,70,20),"Mute") ){
  97. AudioListener.pause = true;
  98. muted = true;
  99. }
  100. } else {
  101.  
  102. // xCoord = screenWidth - (width + margin)
  103. if ( GUI.Button(new Rect(470,35,70,20),"Un-mute") ){
  104. AudioListener.pause = false;
  105. muted = false;
  106. }
  107. } // end if !muted
  108.  
  109. // SCORES
  110. scoreVal = courseScript.score;
  111. // 20.5 * height/21
  112. GUI.Label( new Rect(325, 372, 1000, 300), (scoreText + scoreVal) );
  113.  
  114. PlayerPrefs.GetInt("prevScoreVal");
  115. // 3.5 * height/21
  116. if ( PlayerPrefs.GetInt("prevScoreVal") < 10000 ) {
  117. GUI.Label( new Rect(300, 65, 1000, 300), (prevScoreText + PlayerPrefs.GetInt("prevScoreVal")) );
  118. } else {
  119. GUI.Label( new Rect(300, 65, 1000, 300), (prevScoreText + "-") );
  120. }
  121.  
  122. } // end if ready
  123.  
  124. } // End OnGUI()
  125.  
  126.  
  127. // Allow something to give the right widths and heights
  128. public float[] setDimensions ( float newWidth, float newHeight ) {
  129.  
  130. width = newWidth;
  131. height = newHeight;
  132. float[] dimensions = new float[2] {width, height};
  133.  
  134. return dimensions;
  135. }
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement