miepzerino
2023-12-23 74dd3727f62603f64958790f9e588d47c8f000ff
Assets/Scripts/Managers/GameManager.cs
@@ -5,6 +5,7 @@
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.Tilemaps;
public class GameManager : SettingsManager
{
@@ -12,6 +13,7 @@
    public GameObject healthTextPrefab;
    public Canvas playerUI;
    public Canvas pauseMenuUI;
    public Tilemap tilemap;
    private void Awake()
    {
@@ -23,6 +25,7 @@
        // add listen events
        CharacterEvents.characterDamaged += (CharacterTookDamange);
        CharacterEvents.characterHealed += (CharacterHealed);
        CharacterEvents.characterDrill += (CharacterDrill);
    }
@@ -31,6 +34,7 @@
        // remove listen events
        CharacterEvents.characterDamaged -= (CharacterTookDamange);
        CharacterEvents.characterHealed -= (CharacterHealed);
        CharacterEvents.characterDrill -= (CharacterDrill);
    }
    public void CharacterTookDamange(GameObject character, int damageReceived)
@@ -53,6 +57,34 @@
        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");