Created
April 8, 2019 23:46
-
-
Save DB-009/b9842820ac921bbc3c6f8750757ff730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class GameStateManager : MonoBehaviour | |
{ | |
public playerControls player1;//player reference | |
public TileMapGenerator _mapGen;//map generator reference | |
public List<GameObject> Spheres;//list of sphere that should be off | |
public Camera mainCam;//main camera in scene for basic tracking of player | |
public enum GameState { titleScreen, LoadMap , InGame , Wait};//basic game states | |
public GameState _gameState;//current game state | |
public enum MapGenPhase { off, tileMap, GiantCubes, Explosion , Done };//basic map generator phases | |
public MapGenPhase _mapGenPhase;//current map phase | |
// Start is called before the first frame update | |
void Start() | |
{ | |
_gameState = GameState.titleScreen;//set state to title screen | |
Debug.Log("At Title Screen press Enter to start game"); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if(_gameState == GameState.titleScreen)//if on title screen press enter to start game/generate stage | |
{ | |
if(Input.GetKeyDown(KeyCode.Return)) | |
{ | |
_gameState = GameState.LoadMap;//change game state to load map | |
_mapGenPhase = MapGenPhase.tileMap;//start tile gen phase | |
_mapGen.GenerateMapInital();//generate tiles | |
_mapGenPhase = MapGenPhase.Explosion;//change phase to explode the spheres | |
ExplodeSpheres();//explode the spheres | |
_mapGenPhase = MapGenPhase.Done;//map gen is now complete | |
//Debug.Log("map created turn on player and start camera tracking"); | |
player1.gameObject.SetActive(true);//turn on player | |
mainCam.transform.SetParent(player1.transform);//set camera to child of player | |
} | |
} | |
} | |
public void ExplodeSpheres() | |
{ | |
foreach(GameObject sphere in Spheres) | |
{ | |
sphere.SetActive(true);//turn on spheres | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment