| | |
| | | |
| | | public class GameManager : SettingsManager |
| | | { |
| | | public static bool GameIsPaused = false; |
| | | |
| | | public GameObject damageTextPrefab; |
| | | public GameObject healthTextPrefab; |
| | | public Canvas playerUI; |
| | |
| | | public GenerateTileMap generateTileMap; |
| | | [NonSerialized] |
| | | public List<Vector3Int> destroyedTiles = new List<Vector3Int>(); |
| | | public GameObject pickups; |
| | | |
| | | private void Awake() |
| | | { |
| | | GameIsPaused = false; |
| | | SoundManager.instance.ChangeMusic(SoundName.MusicHappy); |
| | | LoadTileMaps(SaveSystem.isGameLoaded); |
| | | } |
| | |
| | | private void LoadTileMaps(bool loadFromSave) |
| | | { |
| | | generateTileMap = tilemap.GetComponent<GenerateTileMap>(); |
| | | pauseMenuUI.GetComponent<PauseMenu>().Pause(); |
| | | PauseGame(); |
| | | levelChanger.GetComponent<Animator>().SetBool("SceneLoading", true); |
| | | if (loadFromSave) |
| | | { |
| | |
| | | } |
| | | public void GameLoaded() |
| | | { |
| | | pauseMenuUI.GetComponent<PauseMenu>().Resume(); |
| | | ResumeGame(); |
| | | pauseMenuUI.GetComponent<Animator>().SetTrigger("GameLoaded"); |
| | | } |
| | | |
| | |
| | | //Debug.Log(tilemap.HasTile(cellCoord)); |
| | | if (tilemap.HasTile(cellCoord)) |
| | | { |
| | | if (tilemap.GetInstantiatedObject(cellCoord)?.GetComponent<Drillable>()?.isDrillable ?? false) |
| | | GameObject tileGameObject = tilemap.GetInstantiatedObject(cellCoord); |
| | | if (tileGameObject?.GetComponent<Drillable>()?.isDrillable ?? false) |
| | | { |
| | | Vector3 cellWorldPosition = grid.CellToWorld(cellCoord); |
| | | // middle of tile |
| | | cellWorldPosition.x += 0.5f; |
| | | cellWorldPosition.y += 0.5f; |
| | | if (tileGameObject?.GetComponent<Dropable>()?.isDropable ?? false) |
| | | { |
| | | // Change no drops, only inventory |
| | | //Instantiate(tileGameObject?.GetComponent<Dropable>().dropable, cellWorldPosition, Quaternion.identity, pickups.transform); |
| | | Inventory playerInventory = contact.rigidbody.gameObject.GetComponent<Inventory>(); |
| | | if (playerInventory != null) |
| | | { |
| | | playerInventory.AddItem(tileGameObject?.GetComponent<Dropable>().dropable); |
| | | } |
| | | } |
| | | tilemap.SetTile(cellCoord, null); |
| | | destroyedTiles.Add(cellCoord); |
| | | Vector3 moveToPosition = grid.CellToWorld(cellCoord); |
| | | moveToPosition.x += 0.5f; |
| | | moveToPosition.y += 0.5f; |
| | | CharacterEvents.characterDrillingToPosition.Invoke(moveToPosition, drillDirection); |
| | | } |
| | | CharacterEvents.characterDrillingToPosition.Invoke(cellWorldPosition, drillDirection); |
| | | } |
| | | else |
| | | { |
| | | //CharacterEvents.characterDrillingToPositionAbort.Invoke(moveToPosition); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region GameState |
| | | |
| | | public static void PauseGame() |
| | | { |
| | | Time.timeScale = 0f; |
| | | GameIsPaused = true; |
| | | //GameStateEvents.gameStatePauseChanged.Invoke(GameIsPaused); |
| | | } |
| | | public static void ResumeGame() |
| | | { |
| | | Time.timeScale = 1f; |
| | | GameIsPaused = false; |
| | | //GameStateEvents.gameStatePauseChanged.Invoke(GameIsPaused); |
| | | } |
| | | #endregion |
| | | } |