Пример #1
0
        public override IEnumerator RestartSequence()
        {
            MansfeldCharacter.SetPosition(_oldPosition);
            _elapsedTime = 0f;

            var startingPosition = MansfeldCharacter.GetPosition();

            MansfeldCharacter.SetAnimationFloat(AnimationSequence.animationName, 1);

            yield return(new WaitUntil(() =>
            {
                //Return if elapsed time has reached its completion time.
                if (_elapsedTime >= _duration)
                {
                    return true;
                }

                //Calculate the distance traveled by the elapsed time.
                var newDistance = Mathf.InverseLerp(0, _duration, _elapsedTime) * _distance;

                //Calculate the position from the starting position and the forward direction multiplied by the distance.
                var newPosition = startingPosition + MansfeldCharacter.GetForwardVector() * newDistance;

                //Set the new position.
                MansfeldCharacter.SetPosition(newPosition);

                //Increment the elapsed time.
                _elapsedTime += Time.deltaTime;

                return false;
            }));

            MansfeldCharacter.SetAnimationFloat(AnimationSequence.animationName, 0);
            DynamicAnimation.OnAnimationFinishedPlaying();
        }