void Update() { float percentage = timer / targetTime; if (currentState == PendulumState.To || currentState == PendulumState.From) { float adjustedPercentage = smoothCurve.Evaluate(percentage); if (currentState == PendulumState.From) { adjustedPercentage = 1 - adjustedPercentage; } float pos = Mathf.Lerp(StartValue, EndValue, adjustedPercentage); ChangePosition(dimension, pos); } if (timer >= targetTime) { switch (currentState) { case PendulumState.To: //Arrived at end. if (disableAtEnd) { ToggleActive(false); } currentState = PendulumState.AtEnd; targetTime = EndWait; break; case PendulumState.AtEnd: currentState = PendulumState.From; targetTime = FromDuration; break; case PendulumState.From: currentState = PendulumState.AtStart; targetTime = StartWait; break; case PendulumState.AtStart: //Starting Again if (disableAtEnd) { ToggleActive(true); } currentState = PendulumState.To; targetTime = ToDuration; break; case PendulumState.Delayed: currentState = PendulumState.To; targetTime = ToDuration; break; default: break; } timer = 0.0f; } timer += Time.deltaTime; }
void Start() { currentState = PendulumState.Delayed; targetTime = Delay; }