private void Update() { elapsedTime = (elapsedTime + Time.deltaTime) % maxTime; Vector2 velVec = new Vector2(xVelocityCurve.Evaluate(0, controller.ParallaxScroll.x, elapsedTime), yVelocityCurve.Evaluate(0, controller.ParallaxScroll.y, elapsedTime)); controller.ParallaxScroll = velVec; }
private IEnumerator AnimateSpeedTo(float value, PhysicsAnimationCurve curveFrom, PhysicsAnimationCurve curveTo) { float elapsed = 0.0f; float duration = curveFrom.TimeMultiplier; float startSpeed = gameSpeed; if (Mathf.Sign(value) != Mathf.Sign(gameSpeed) && gameSpeed != 0) { while (elapsed < duration) { if (IsPaused) { yield return(new WaitForEndOfFrame()); continue; } gameSpeed = curveFrom.Evaluate(gameSpeed, duration - elapsed) * startSpeed; elapsed += Time.deltaTime; OnSpeedChangeEvent?.Invoke(); yield return(new WaitForEndOfFrame()); } elapsed = gameSpeed = 0; } duration = curveTo.TimeMultiplier; while (elapsed < duration) { if (IsPaused) { yield return(new WaitForEndOfFrame()); continue; } gameSpeed = curveTo.Evaluate(gameSpeed, elapsed) * value; elapsed += Time.deltaTime; OnSpeedChangeEvent?.Invoke(); yield return(new WaitForEndOfFrame()); } gameSpeed = value; OnSpeedChangeEvent?.Invoke(); }