Advertisement
LittleAngel

increment

Feb 17th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. IEnumerator AlignToChapter () { // Co-routine for animating the "snap" to the current chapter when the user releases
  2. bool aligning = true; // Create and Set all of the current values in preparation of "lerping"
  3. float startTime = Time.time;
  4. float currentLocation = navBar.Value;
  5. float closestChapter = increment * (Mathf.Round(navBar.Value/increment));
  6. while (aligning) { // While aligning: Lerp the Nav Bar Know location to the next closest chapter
  7. navBar.Value = Mathf.Lerp (currentLocation, closestChapter, (Time.time - startTime) * alignmentSpeed);
  8. if (Mathf.Abs (closestChapter - navBar.Value) < threshold) {
  9. navBar.Value = closestChapter;
  10. aligning = false;
  11. }
  12. yield return null;
  13. }
  14.  
  15. guiController.GoToChapter (currentChapter); // Enable code here for triggering of new chapter AFTER the knob has settled
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement