Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class GameManager : MonoBehaviour {
- //Count
- public int currentScore;
- public int highscore;
- public int tokenCount;
- private int totalTokenCount;
- public int currentLevel = 0;
- public int unlockedLevel;
- //Timer variables
- public Rect timerRect;
- public Color warningColorTimer;
- public Color defaultColorTimer;
- public float startTime;
- private string currentTime;
- //GUI Skin
- public GUISkin skin;
- //References
- public GameObject tokenParent;
- private bool completed = false;
- private bool showWinScreen = false;
- public int winScreenWidth, winScreenHeight;
- void Update()
- {
- if(!completed){
- startTime -= Time.deltaTime;
- currentTime = string.Format ("{0:0.0}", startTime);
- if (startTime <= 0)
- {
- startTime = 0;
- //Application.LoadLevel("main_menu");
- }}
- }
- void Start()
- {
- totalTokenCount = tokenParent.transform.childCount;
- if (PlayerPrefs.GetInt ("Level Completed") > 1)
- {
- currentLevel += PlayerPrefs.GetInt ("Level Completed");
- } else {
- currentLevel = 1;
- }
- }
- public void CompleteLevel()
- {
- showWinScreen = true;
- completed = true;
- }
- void LoadNextLevel()
- { Time.timeScale = 1f;
- if (currentLevel < 3)
- {
- currentLevel += 1;
- print (currentLevel);
- SaveGame ();
- Application.LoadLevel(currentLevel);
- } else {
- print ("You win");
- }
- }
- void SaveGame()
- {
- PlayerPrefs.SetInt ("Level Completed", currentLevel);
- PlayerPrefs.SetInt ("Level " + currentLevel.ToString() + " score", currentScore);
- }
- public void AddToken()
- {
- if (currentLevel < 3) {
- tokenCount += 1;
- }
- }
- void OnGUI()
- {
- GUI.skin = skin;
- if (startTime < 10f) {
- skin.GetStyle ("Timer").normal.textColor = warningColorTimer;
- } else {
- skin.GetStyle ("Timer").normal.textColor = defaultColorTimer;
- }
- GUI.Label (timerRect, currentTime, skin.GetStyle ("Timer"));
- GUI.Label (new Rect(45, 100, 200, 200), tokenCount.ToString()+ "/" + totalTokenCount.ToString());
- if (showWinScreen)
- {
- Rect winScreenRect = new Rect(Screen.width/2 - (Screen.width*.5f/2), Screen.height/2 - (Screen.height*.5f/2), Screen.width*.5f, Screen.height*.5f);
- GUI.Box(winScreenRect, "Yeah");
- //LUCAS LOOK HERE TO EDIT SCORING!!
- int gameTime = (int)startTime;
- float currentScore = (tokenCount*5) + gameTime;
- if(GUI.Button(new Rect(winScreenRect.x + winScreenRect.width - 170, winScreenRect.y + winScreenRect.height -60, 150, 40), "Continue"))
- {
- Application.LoadLevel (4);
- }
- if(GUI.Button(new Rect(winScreenRect.x + 20, winScreenRect.y + winScreenRect.height -60, 100, 40), "Quit"))
- {
- Application.LoadLevel ("main_menu");
- Time.timeScale = 1f;
- }
- GUI.Label (new Rect(winScreenRect.x + 20, winScreenRect.y + 40, 300, 50), currentScore.ToString () + ( " Score"));
- GUI.Label (new Rect(winScreenRect.x + 20, winScreenRect.y + 70, 300, 50), "Completed Level " + (currentLevel));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement