// Update is called once per frame void Update() { // Start Update. switch( gameState ) { // Start gameStae switch. case GameGlobals.GameState.running: { // Start Game Running Case // If escape is pressed then we bring up the menu: if( Input.GetAxis( "Cancel/Exit" ) == 1 && axesInputDelayControl.AxesInputCoolDownTimer == 0.0f) { axesInputDelayControl.actavateCoolDownTimer(); pauseGame(); } else { _playTime += Time.deltaTime; if( pauseMenu.activeSelf ) pauseMenu.SetActive( false ); } break; } // End Game Running Case. case GameGlobals.GameState.Menu: { // If escape is pressed then we return to the game: if( Input.GetAxis( "Cancel/Exit" ) == 1 && axesInputDelayControl.AxesInputCoolDownTimer == 0.0f ) { axesInputDelayControl.actavateCoolDownTimer(); gameState = GameGlobals.GameState.running; } break; } case GameGlobals.GameState.Paused: { // If escape or p is pressed then we return to the game if( Input.GetAxis( "Cancel/Exit" ) == 1 && axesInputDelayControl.AxesInputCoolDownTimer == 0.0f ) { axesInputDelayControl.actavateCoolDownTimer(); gameState = GameGlobals.GameState.running; } break; } } // End gameStae switch. }
public void pauseGame() { gameState = GameGlobals.GameState.Paused; //playerScript.LockCursor = false; // Bring up the menu: if( !pauseMenu.activeSelf ) pauseMenu.SetActive( true ); }
void Initialize() { // Getting Game system refrecnces: if( _gameData == null ) _gameData = GameData.getInstance(); if( axesInputDelayControl == null ) axesInputDelayControl = AxesInputDelayControl.getInstance(); // Preseting data here since UNITY seems to ignore anything global: MapWidth = (int)MazeGlobals.SMALL_MAP_SIZE.x; MapHeight = (int)MazeGlobals.SMALL_MAP_SIZE.y; // XML/Saving data: isSavable = true; //Globals.defaultIsSavable; xmlElementName = MazeGlobals.mazeXMLlElementNameDefault; xmlNamespace = MazeGlobals.mazeXMLNamespaceDefault; savePathAndName = MazeGlobals.mazeSavePathAndNameDefault; // Initalizing the list to hold the maps: if( _mapList == null ) _mapList = new GenericManager<int, Map>( isSavable, xmlElementName, xmlNamespace, savePathAndName ); // Loading a floor if needed: if( FloorObj == null ) { FloorObj = GameObject.CreatePrimitive( PrimitiveType.Cube ); FloorObj.name = GameGlobals.FLOOR_BLOCK_NAME; FloorObj.tag = GameGlobals.FLOOR_BLOCK_TAG; FloorObj.renderer.material = Resources.Load( GameGlobals.FLOOR_BLOCK_MAT, typeof(Material)) as Material;; FloorObj.renderer.material.shader = Shader.Find( GameGlobals.floorShaderList[ (int) SettingsData.getInstance().GameDifficulty ] ); FloorObj.transform.localScale = GameGlobals.floorSize; } // Loading a wall if needed: if( WallObj == null ) { WallObj = GameObject.CreatePrimitive( PrimitiveType.Cube ); WallObj.name = GameGlobals.WALL_BLOCK_NAME; WallObj.tag = GameGlobals.WALL_BLOCK_TAG; WallObj.renderer.material = Resources.Load( ( GameGlobals.WALL_BLOCK_RANDOM_MAT + Random.Range( 2, 13).ToString() ), typeof(Material)) as Material;; //WallObj.renderer.material.shader = Shader.Find( GameGlobals.wallShaderList[ (int) _gameData.settings.GameDifficulty ] ); WallObj.transform.localScale = GameGlobals.wallSize; } // If the wal or floor are null then exit: if( FloorObj == null || WallObj == null ) { Debug.Log("Error wall and/or floor are not initalized"); return; } #region Creating the light // Creating the light: if( AreaLight == null ) { //AreaLight = new GameObject("The Light"); //AreaLight.AddComponent<Light>(); //AreaLight.light.color = AreaLightColor; //AreaLight.light.type = LightType.Directional; //AreaLight.light.intensity = 0.5f; //AreaLight.transform.localRotation = new Quaternion( 90, 0, 0, 0 ); //AreaLight.transform.position = new Vector3( ( MapWidth * FloorSize.x ) / GameGlobals.HALF, ( FloorSize.y + WallSize.y ) * 10, ( MapHeight * FloorSize.z ) / GameGlobals.HALF ); } #endregion #region Map Loading/Gernerating Generator = new MazeGenerator(); // Attempting to laod an XML file and make the first maze, // If this does not work then we load the default maze: if( !_mapList.loadObjectList( false, Path.Combine( Application.dataPath, savePathAndName ), xmlElementName, xmlNamespace ) ) { // Creating the default raw map data: MainMap = new Map(); MainMap.initalizeDefaultMap(false); // Transforming the default raw map data into Unity objects: Generator.genrate( ref MainMap, ref MapWidth, ref MapHeight, ref FloorObj, ref WallObj ); _mapList.addObject( _mapList.Listcount, MainMap ); // Adding aditional raw map data as needed: AddingMazeHelper.mazeListToAdd( ref _mapList ); // Use this to add lots of maps. // Saving the raw map data to xml: _mapList.saveObjectList( Path.Combine( Application.dataPath, savePathAndName ), xmlElementName, xmlNamespace ); } else { MainMap = _mapList.getObject(0); MainMap.initalizeLoadedMap( false ); Generator.genrate( ref MainMap, ref MapWidth, ref MapHeight, ref FloorObj, ref WallObj ); } #endregion #region Creating Start and End Positions // Creating the Start Position Marker: if( StartPoint == null ) { StartVector = MainMap.playerStartPoint; StartVector.x = (StartVector.x) * FloorObj.transform.localScale.x; StartVector.z = (StartVector.z) * FloorObj.transform.localScale.z; StartPoint = GameObject.CreatePrimitive( PrimitiveType.Cube ); StartPoint.name = GameGlobals.START_POSITION_NAME; StartPoint.tag = GameGlobals.START_POSITION_TAG; StartPoint.transform.localScale = GameGlobals.startAndEndMarkerSize; StartPoint.transform.position = new Vector3( StartVector.x, StartPoint.transform.localScale.y, StartVector.z); StartMat = Resources.Load( GameGlobals.START_BLOCK_MAT, typeof(Material)) as Material; StartPoint.renderer.material = StartMat; } // Creating the End Position Marker: if( EndPoint == null ) { EndVector = MainMap.playerEndPoint; EndVector.x = EndVector.x * FloorObj.transform.localScale.x; EndVector.z = EndVector.z * FloorObj.transform.localScale.z; EndPoint = GameObject.CreatePrimitive( PrimitiveType.Sphere ); EndPoint.name = GameGlobals.END_POSITION_NAME; EndPoint.tag = GameGlobals.END_POSITION_TAG; EndPoint.transform.localScale = GameGlobals.startAndEndMarkerSize; EndPoint.transform.position = new Vector3( EndVector.x, EndPoint.transform.localScale.y, EndVector.z ); ; EndMat = Resources.Load( GameGlobals.END_BLOCK_MAT, typeof(Material)) as Material; EndPoint.renderer.material = EndMat; EndPoint.collider.isTrigger = true; EndPoint.AddComponent<EndPointScript>(); } #endregion #region Creating the Player // Creating the Player and puting it in the game: //Player = Instantiate( Resources.Load( "Player" , typeof(GameObject)) ) as GameObject; Player = Instantiate( Resources.Load( "Prefabs/FPSPlayer" , typeof(GameObject)) ) as GameObject; Player.name = "FPSPlayer"; Player.transform.position = new Vector3 ( StartVector.x, 2, StartVector.z ); playerScript = Player.GetComponent<vp_FPSPlayer>(); #endregion // Setting up gameplay variables: gameState = GameGlobals.GameState.running; // Interface Variables _playTime = 0.0f; _playTimePosition = new Rect( Screen.width - 50, 20, 50, 50 ); #region Pause Button // Seting up the pause Button: //_pauseTextureList = new Texture[ GUIGlobals.numberOfButtonStates ]; //_pauseButtonPosition = new Rect( 0, Screen.height - 50, 100, 50 ); //listCount = _pauseTextureList.Length; //for( i = 0; i < listCount; i++ ) //_pauseTextureList[i] = (Texture2D)Resources.Load( GUIGlobals.pauseButtonPathList[i], typeof(Texture2D)); #endregion #region Pause Menu // Creating the Pause Menu: pauseMenu = new GameObject(); pauseMenu.name = PauseMenuGlobals.PAUSE_MENU_NAME; pauseMenu.tag = PauseMenuGlobals.PAUSE_MENU_TAG; pauseMenu.AddComponent<MenuBase>(); pauseMenu.GetComponent<MenuBase>().initialize( GUIGlobals.menuTypeDefs.PAUSE, PauseMenuGlobals.PAUSE_MENU_BACKGROUND_PATH, PauseMenuGlobals.PAUSE_MENU_BUTTON_TEXTURES, PauseMenuGlobals.PAUSE_MENU_TOOL_TIPS, PauseMenuGlobals.PAUSE_MENU_BUTTON_POSITIONS ); pauseMenu.SetActive( false ); #endregion // Cleaning up the origanal wall and floor objects: Destroy(WallObj); Destroy(FloorObj); }