Exemplo n.º 1
0
    private void Update()
    {
        if (shouldBeMoving)
        {
            while (ipath < path.Count - 1 && !UF.CheckForMapCollider(transform.position, path[ipath + 1]))
            {
                ipath++;
            }
            Vector2 nextPoint         = path[ipath];
            Vector2 movementDirection = (nextPoint - (Vector2)transform.position).normalized;
            rb.velocity = movementDirection * speed;

            if (Mathf.Abs(movementDirection.x) > Mathf.Abs(movementDirection.y))
            {
                if (movementDirection.x > 0)
                {
                    animator.SetInteger("Direction", 2);
                }
                else
                {
                    animator.SetInteger("Direction", 0);
                }
            }
            else
            {
                if (movementDirection.y > 0)
                {
                    animator.SetInteger("Direction", 1);
                }
                else
                {
                    animator.SetInteger("Direction", 3);
                }
            }

            if (UF.DistanceBetween2Units(transform.position, goal) < 0.05f)
            {
                StopMoving();
                if (currentTarget != null)
                {
                    currentTarget.SendMessage("Activate");
                    currentTarget = null;
                }
            }
        }
    }