| | |
| | | using UnityEngine; |
| | | using UnityEngine.InputSystem; |
| | | using UnityEngine.SceneManagement; |
| | | using UnityEngine.Tilemaps; |
| | | |
| | | public class GameManager : SettingsManager |
| | | { |
| | |
| | | public GameObject healthTextPrefab; |
| | | public Canvas playerUI; |
| | | public Canvas pauseMenuUI; |
| | | public Tilemap tilemap; |
| | | |
| | | private void Awake() |
| | | { |
| | |
| | | // add listen events |
| | | CharacterEvents.characterDamaged += (CharacterTookDamange); |
| | | CharacterEvents.characterHealed += (CharacterHealed); |
| | | CharacterEvents.characterDrill += (CharacterDrill); |
| | | |
| | | } |
| | | |
| | |
| | | // remove listen events |
| | | CharacterEvents.characterDamaged -= (CharacterTookDamange); |
| | | CharacterEvents.characterHealed -= (CharacterHealed); |
| | | CharacterEvents.characterDrill -= (CharacterDrill); |
| | | } |
| | | |
| | | public void CharacterTookDamange(GameObject character, int damageReceived) |
| | |
| | | tmpText.text = healthRestored.ToString(); |
| | | |
| | | } |
| | | public void CharacterDrill(ContactPoint2D contact, DrillDirection drillDirection) |
| | | { |
| | | GridLayout grid = tilemap.transform.GetComponentInParent<GridLayout>(); |
| | | Vector3Int cellCoord = grid.WorldToCell(contact.point); |
| | | switch (drillDirection) |
| | | { |
| | | case DrillDirection.Left: |
| | | cellCoord.x = cellCoord.x - 1; |
| | | break; |
| | | case DrillDirection.Right: |
| | | cellCoord.x = cellCoord.x + 1; |
| | | break; |
| | | case DrillDirection.Down: |
| | | cellCoord.y = cellCoord.y - 1; |
| | | break; |
| | | } |
| | | |
| | | //Debug.Log("cellCoord: " + grid.CellToWorld(cellCoord)); |
| | | //Debug.Log(tilemap.HasTile(cellCoord)); |
| | | if (tilemap.HasTile(cellCoord)) |
| | | { |
| | | tilemap.SetTile(cellCoord, null); |
| | | Vector3 moveToPosition = grid.CellToWorld(cellCoord); |
| | | moveToPosition.x += 0.5f; |
| | | moveToPosition.y += 0.5f; |
| | | CharacterEvents.characterDrillingToPosition.Invoke(moveToPosition); |
| | | } |
| | | } |
| | | public void GameLoaded() |
| | | { |
| | | pauseMenuUI.GetComponent<Animator>().SetTrigger("GameLoaded"); |