Ejemplo n.º 1
0
    private IEnumerator TestCoroutine(Vector2 waypoint)
    {
        var direction = (waypoint - new Vector2(transform.localPosition.x, transform.localPosition.y));

        direction.Normalize();

        switch (Mathf.Round(Vector2.SignedAngle(Vector2.right, direction)))
        {
        case 0:
            AnimationController.Right();
            break;

        case -90:
            AnimationController.Down();
            break;

        case 90:
            AnimationController.Top();
            break;

        case 180:
            AnimationController.Left();
            break;
        }

        while (Vector2.Distance(transform.localPosition, waypoint) > 1f)
        {
            transform.localPosition = Vector2.MoveTowards(transform.localPosition, waypoint, Data.MovingSpeed);

            yield return(new WaitForSecondsRealtime(.02f));
        }

        Move();
    }