Ejemplo n.º 1
0
    public void MoveEnemy()
    {
        Vector2 dis = target.position - transform.position;

        isMove = true;
        if (dis.sqrMagnitude > distance * distance)
        {
            isMove = false;
            return;
        }
        gridPath.CreateGrid();
        Vector2 dir  = pathfinding.FindPath(transform.position, target.position);
        int     xDir = Mathf.RoundToInt(dir.x - transform.position.x);
        int     yDir = Mathf.RoundToInt(dir.y - transform.position.y);

        if (xDir > 0)
        {
            onLeft = false;
            animator.ResetTrigger("Left");
            animator.SetTrigger("Right");
            animator.SetBool("LeftBool", false);
        }
        else if (xDir < 0)
        {
            onLeft = true;
            animator.ResetTrigger("Right");
            animator.SetTrigger("Left");
            animator.SetBool("LeftBool", true);
        }

        AttemptMove <Player>(xDir, yDir);
    }
Ejemplo n.º 2
0
    public override void MoveBoss()
    {
        counterDark++;
        if (counterDark == 7)
        {
            counterDark = 0;
        }
        if (counterDark < 2 || counterDark == 4 || counterDark == 5)
        {
            return;
        }

        gridPath.CreateGrid();
        Vector2 dir  = pathfinding.FindPath(transform.position, player.transform.position);
        int     xDir = Mathf.RoundToInt(dir.x - transform.position.x);
        int     yDir = Mathf.RoundToInt(dir.y - transform.position.y);

        if (xDir > 0)
        {
            bossAnimator.ResetTrigger("Left");
            bossAnimator.SetTrigger("Right");
        }
        else if (xDir < 0)
        {
            bossAnimator.ResetTrigger("Right");
            bossAnimator.SetTrigger("Left");
        }

        RaycastHit2D hit;
        bool         canMove = Move(xDir, yDir, out hit);

        if (hit.transform == null)
        {
            return;
        }
        Player hitComponent = hit.transform.GetComponent <Player>();

        if (!canMove && hitComponent != null)
        {
            hitComponent.TakeHit(damage, true, gameObject);
        }
    }