using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameController : MonoBehaviour{ public string menuScene; public string[] scenes; public bool reversed; public Image timeBar; public float maxTime; float currentTime; // Start is called before the first frame update void Start(){ currentTime = maxTime; if (PlayerPrefs.HasKey("CurrentScore")){ PlayerPrefs.SetInt("CurrentScore", PlayerPrefs.GetInt("CurrentScore") + 1); }else{ PlayerPrefs.SetInt("CurrentScore", 0); } } // Update is called once per frame void Update(){ currentTime -= 1 * Time.deltaTime; timeBar.transform.localScale = new Vector2(currentTime / maxTime, timeBar.transform.localScale.y); if(currentTime <= 0){ if (reversed){ CompleteLevel(); }else{ LoseGame(); } } } public void CompleteLevel(){ string scene = scenes[Random.Range(0, scenes.Length - 1)]; LevelLoader.Instance.LoadLevel(scene); } public void LoseGame(){ Debug.LogError(SceneManager.GetActiveScene().name); LevelLoader.Instance.LoadLevel(menuScene); } }