Advertisement
Guest User

Making a Simple Game / jumps to level 3 at start / timer doe

a guest
Jul 24th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GameManager : MonoBehaviour {
  5.  
  6.  
  7. //Count
  8. public int currentScore;
  9. public int highScore;
  10. public int tokenCount;
  11. private int totalTokenCount;
  12. public int currentLevel = 0;
  13. public int unlockedLevel;
  14.  
  15. //Timer variables
  16. public Rect timerRect;
  17. public Color warningColorTimer;
  18. public Color defaultColorTimer;
  19. public float startTime;
  20. private string currentTime;
  21.  
  22. // GHI Skin
  23. public GUISkin skin;
  24.  
  25. // References
  26. public GameObject tokenParent;
  27.  
  28. private bool completed = false;
  29. private bool showWinScreen = false;
  30. public int winScreenWidth, winScreenHeight;
  31.  
  32. void Reset()
  33. {
  34. completed = false;
  35. showWinScreen = false;
  36. currentLevel = 0;
  37. }
  38.  
  39. void Update()
  40. {
  41. if (!completed)
  42. {
  43. startTime -= Time.deltaTime;
  44. currentTime = string.Format("(0:0.0)",startTime);
  45. if (startTime <= 0)
  46. {
  47. startTime = 0;
  48. //Application.LoadLevel("MainMenu");
  49. }
  50. }
  51. }
  52.  
  53.  
  54. void Start()
  55. {
  56. totalTokenCount = tokenParent.transform.childCount;
  57.  
  58. if (PlayerPrefs.GetInt ("Level Complete") > 0)
  59. {
  60. currentLevel = PlayerPrefs.GetInt ("Level Complete");
  61. }
  62. else
  63. {
  64. currentLevel = 0;
  65. }
  66. //DontDestroyOnLoad(gameObject);
  67. print ("you are on " + currentLevel);
  68. }
  69.  
  70.  
  71. public void CompleteLevel()
  72. {
  73. showWinScreen = true;
  74. completed = true;
  75. }
  76.  
  77.  
  78. void LoadNextLevel()
  79. {
  80. Time.timeScale = 1f;
  81. if (currentLevel < 2)
  82. {
  83. currentLevel += 1;
  84. print (currentLevel);
  85. SaveGame();
  86. Application.LoadLevel(currentLevel);
  87. }
  88. else
  89. {
  90. print ("You won the game");
  91. }
  92. }
  93.  
  94.  
  95. void SaveGame()
  96. {
  97. PlayerPrefs.SetInt("Level Completed", currentLevel);
  98. PlayerPrefs.SetInt("Level " + currentLevel.ToString() + "score", currentScore);
  99.  
  100. }
  101.  
  102. void OnGUI()
  103. {
  104. GUI.skin = skin;
  105. if (startTime < 5f)
  106. {
  107. skin.GetStyle ("Timer").normal.textColor = warningColorTimer;
  108. }
  109. else
  110. {
  111. skin.GetStyle ("Timer").normal.textColor = defaultColorTimer;
  112. }
  113.  
  114. GUI.Label (timerRect, currentTime, skin.GetStyle ("Timer"));
  115. GUI.Label (new Rect(45, 100, 200, 200), tokenCount.ToString() + "/" + totalTokenCount.ToString());
  116.  
  117. if (showWinScreen)
  118. {
  119. Rect winScreenRect = new Rect(Screen.width/2 - (Screen.width * .5f/2), Screen.height/2 -(Screen.height * .5f/2), Screen.width * .5f, Screen.height * .5f);
  120. GUI.Box(winScreenRect, "Yeah");
  121.  
  122. int gameTime = (int)startTime;
  123. currentScore = tokenCount * gameTime;
  124. if (GUI.Button(new Rect(winScreenRect.x + winScreenRect.width - 170, winScreenRect.y + winScreenRect.height - 60, 150,40), "Continue"))
  125. {
  126. LoadNextLevel();
  127.  
  128. }
  129.  
  130. if (GUI.Button(new Rect(winScreenRect.x + 20, winScreenRect.y + winScreenRect.height - 60, 100,40), "Quit"))
  131. {
  132. Application.LoadLevel("MainMenu");
  133. Time.timeScale = 1f;
  134.  
  135. }
  136.  
  137. GUI.Label(new Rect(winScreenRect.x + 20, winScreenRect.y + 40, 300, 50), currentScore.ToString() + " Score");
  138. GUI.Label(new Rect(winScreenRect.x + 20, winScreenRect.y + 70, 300, 50), "Completed Level " + currentLevel);
  139. }
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement