Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        currentPosition = transform.position;

        if (Mathf.RoundToInt(actualTarget.x) != Mathf.RoundToInt(prevTarget.x) ||
            Mathf.RoundToInt(actualTarget.y) != Mathf.RoundToInt(prevTarget.y))
        {
            pathFinding.startPos = tilemapHandler.PositionToTilemapNode(currentPosition).position;
            pathFinding.goalPos  = tilemapHandler.PositionToTilemapNode(actualTarget).position;
            pathFinding.FindPath();
            prevTarget = actualTarget;

            if (pathFinding.path != null && pathFinding.path.Count > 0)
            {
                targetPosition = pathFinding.path.Pop();
            }
            else
            {
                targetPosition = transform.position;
            }


            targetPosition.y += 1.5f;
        }

        if (Mathf.RoundToInt(currentPosition.x) != Mathf.RoundToInt(targetPosition.x) ||
            Mathf.RoundToInt(currentPosition.y) != Mathf.RoundToInt(targetPosition.y))
        {
            MoveToTargetPosition();
        }
        else
        {
            if (pathFinding.path != null && pathFinding.path.Count > 0)
            {
                targetPosition    = pathFinding.path.Pop();
                targetPosition.y += 1.5f;
            }
        }
    }