Example #1
0
    private IEnumerator EasedLerpPosition(Vector2 start, Vector2 destination, EasingType easingType = EasingType.EaseLinear, Action onFinishMoveAlongPath = null)
    {
        float time = 0.0f;

        float fromToOnPathDistance = Vector3.Distance(start, destination);

        float duration = fromToOnPathDistance / speed;

        while (time < duration)
        {
            float progress      = time / duration;
            float easedProgress = EasingHelper.Ease(easingType, progress);

            time += Time.deltaTime;

            transform.position = Vector2.Lerp(start, destination, easedProgress);

            yield return(new WaitForEndOfFrame());
        }

        yield return(new WaitForEndOfFrame());

        if (onFinishMoveAlongPath != null)
        {
            onFinishMoveAlongPath();
        }
    }