Roguelike 2D tutorial

Hello.

I did whole Rogouelike 2D tutorial from youtube. I wanted extend this to the simple combat system (in the same way like player can destroy walls) but i got two problems. I added function to class MovingObject to detect colision with enemy.

    protected virtual void AttemptMove <T> (int xDir, int yDir)
        where T: Component
    {
        RaycastHit2D hit;
        bool canMove = Move(xDir, yDir, out hit);

        if (hit.transform == null)
            return;

        GameObject hitComponent = hit.transform.gameObject;

        if (!canMove && hitComponent != null)
        {
            if (hitComponent.GetComponent<Wall>() != null)
            {
                Component hitCom = hitComponent.GetComponent<Wall>();
                OnCantMove(hitCom);
            }
            else if (hitComponent.GetComponent<Enemy>() != null)
            {
                Component hitCom2 = hitComponent.GetComponent<Enemy>();
                OnCantMove(hitCom2);
            }

            else if (hitComponent.GetComponent<Player>() != null)
            {
                Component hitCom2 = hitComponent.GetComponent<Player>();
                OnCantMove(hitCom2);
            }
        }
    }

This works nice, enemy take my food points on colision but after killing Enemy stuck on this plase like invisible and still my character lost food points. When i added function to set gameobject like inacteve when hp points aer <= 0 player cant move. Console said problem is in this function.

   public void MoveEnemy()
    {
        int xDir = 0;
        int yDir = 0;

        if (Mathf.Abs(target.position.x - transform.position.x) < float.Epsilon)
            yDir = target.position.y > transform.position.y ? 1 : -1;
        else
            xDir = target.position.x > transform.position.x ? 1 : -1;

        AttemptMove<Player>(xDir, yDir);
    }

Any ideas how to fix that?

If your player still loosing HP(or FP) is probably that the enemy script is still executing. I think you need to destroy the enemy when is dead.

If your players moves before combat it should move after without problems.