private IEnumerator DelayedPlayerStart() { yield return(new WaitForSeconds(1f)); _playerPiece = Instantiate(PrefabManager.GetPrefab(PrefabManager.PrefabType.PlayerPiece), Vector3.zero, Quaternion.identity) .GetComponent <PlayerPieceController>(); if (GridLevel == 2) { _playerPiece.ConvertPlayerPieceType(PlayerPieceController.PlayerPieceType.Destroy); } else if (GridLevel == 3) { _playerPiece.ConvertPlayerPieceType(PlayerPieceController.PlayerPieceType.Mirror); _playerMirrorPiece = Instantiate(PrefabManager.GetPrefab(PrefabManager.PrefabType.PlayerPiece), Vector3.zero, Quaternion.identity) .GetComponent <PlayerPieceController>(); _playerMirrorPiece.ConvertPlayerPieceType(PlayerPieceController.PlayerPieceType.Mirror); _playerMirrorPiece.PlaceOnTop(ActiveGrid.Pieces[4, 4]); } _playerPiece.PlaceOnTop(ActiveGrid.Pieces[0, 0]); }
private void Update() { int x = (int)Input.GetAxisRaw("Horizontal"); int z = (int)Input.GetAxisRaw("Vertical"); if (Input.GetKeyDown(KeyCode.G)) { if (_meteor == null) { _meteor = Instantiate(PrefabManager.GetPrefab(PrefabManager.PrefabType.Meteor)).GetComponent <MeteorController>(); StartCoroutine(MeteorPause()); _gameStarted = false; } return; } if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } if (!_gameStarted) { return; } if (Input.anyKeyDown) { if (_playerMoving) { return; } if (Mathf.Abs(x) > 0f || Mathf.Abs(z) > 0f) { if (_playerPiece.PPieceType == PlayerPieceController.PlayerPieceType.Mirror) { PieceController nextPiece = ActiveGrid.ProcessInput(_playerPiece.GridPosition, new Vector2Int(x, z)); if (nextPiece != null) { StartCoroutine(AnimatePlayerMovement(_playerPiece, nextPiece)); } nextPiece = ActiveGrid.ProcessInput(_playerMirrorPiece.GridPosition, new Vector2Int(x * -1, z * -1)); if (nextPiece != null) { StartCoroutine(AnimatePlayerMovement(_playerMirrorPiece, nextPiece)); } } else { PieceController nextPiece = ActiveGrid.ProcessInput(_playerPiece.GridPosition, new Vector2Int(x, z)); if (nextPiece != null) { StartCoroutine(AnimatePlayerMovement(_playerPiece, nextPiece)); } } } if (Input.GetKeyDown(KeyCode.Space)) { if (_playerPiece.PPieceType == PlayerPieceController.PlayerPieceType.Destroy) { PieceController destroyedPiece = _playerPiece.DestroyAction(); if (destroyedPiece != null) { ActiveGrid.PlayingPieces.Remove(destroyedPiece); } } else if (_playerPiece.PPieceType == PlayerPieceController.PlayerPieceType.Normal) { _playerPiece.ConvertPieceType(PieceController.PieceType.Normal); ActiveGrid.AddPlayingPiece(_playerPiece); } else if (_playerPiece.PPieceType == PlayerPieceController.PlayerPieceType.Mirror) { _playerPiece.ConvertPieceType(PieceController.PieceType.Normal); ActiveGrid.AddPlayingPiece(_playerPiece); _playerMirrorPiece.ConvertPieceType(PieceController.PieceType.Normal); ActiveGrid.AddPlayingPiece(_playerMirrorPiece); } _cubesUsed++; if (ActiveGrid.CheckComplete()) { PlaceCivsOnPiece(ActiveGrid.Pieces[1, 1]); StartCoroutine(SceneTransition()); _gameStarted = false; } else { _playerPiece = Instantiate(PrefabManager.GetPrefab(PrefabManager.PrefabType.PlayerPiece), Vector3.zero, Quaternion.identity) .GetComponent <PlayerPieceController>(); if (GridLevel == 3) { if (_cubesUsed == 1) { _playerPiece.ConvertPlayerPieceType(PlayerPieceController.PlayerPieceType.Destroy); } } _playerPiece.PlaceOnTop(ActiveGrid.Pieces[0, 0]); } //_playerPiece.ConvertPlayerPieceType(PlayerPieceController.PlayerPieceType.Destroy); } } }