Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class GameManager : MonoBehaviour
- {
- public float levelStartDelay = 2.2f;
- public float turnDelay = .1f;
- public static GameManager instance = null;
- public BoardManager boardScript;
- public int playerFoodPoints = 100;
- [HideInInspector] public bool playersTurn = true;
- private int level = 1 ;
- private List<Enemy> enemies;
- private bool enemiesMoving;
- private Text levelText;
- private GameObject levelImage;
- private bool doingSetup;
- // Start is called before the first frame update
- void Awake()
- {
- Debug.Log("GM: Awake" );
- if ( instance == null ){
- instance = this;
- }else if( instance != this){
- Destroy(gameObject);
- }
- DontDestroyOnLoad(gameObject);
- enemies = new List<Enemy>();
- boardScript = GetComponent<BoardManager>();
- InitGame();
- }
- private void OnLevelWasLoaded( int index)
- {
- level++;
- Debug.Log("GM: OnLevelWasLoaded" + level);
- InitGame();
- }
- void InitGame()
- {
- doingSetup = true;
- levelImage = GameObject.Find("LevelImage");
- levelText = GameObject.Find("LevelText").GetComponent<Text>();
- levelText.text = "Day " + level;
- levelImage.SetActive(true);
- Invoke("HideLevelImage", levelStartDelay);
- enemies.Clear();
- boardScript.SetupScene(level);
- }
- private void HideLevelImage()
- {
- levelImage.SetActive(false);
- doingSetup = false;
- }
- public void GameOver()
- {
- levelText.text = "After " + level + " days, you starved.";
- levelImage.SetActive(true);
- enabled = false;
- }
- IEnumerator MoveEnemies()
- {
- enemiesMoving= true;
- yield return new WaitForSeconds(turnDelay);
- if( enemies.Count == 0){
- yield return new WaitForSeconds(turnDelay);
- }
- for(int i=0;i< enemies.Count ; i++){
- enemies[i].MoveEnemy();
- yield return new WaitForSeconds(enemies[i].moveTime);
- }
- playersTurn = true;
- enemiesMoving = false;
- }
- // Update is called once per frame
- void Update()
- {
- if(playersTurn || enemiesMoving || doingSetup)
- return ;
- //https://docs.unity3d.com/530/Documentation/ScriptReference/Application.Quit.html
- if (Input.GetKey("escape")){
- Application.Quit();
- }
- StartCoroutine(MoveEnemies());
- }
- public void AddEnemyToList(Enemy script){
- enemies.Add(script);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement