init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
48
Assets/Scripts/GameController.cs
Normal file
48
Assets/Scripts/GameController.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue