Advertisement
Guest User

Untitled

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