Author Topic: Another slider issue  (Read 2763 times)

NineTails

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Another slider issue
« on: March 21, 2014, 07:03:46 AM »
This is a follow on from my last message which helped. Thank you.

In my scene I have a list of elapsed days between two points created by the DataTime class in C#. This returns a double.

I'm now trying to make it so my slider will return the day in the list as it scrolls along. For example if I have 30 elements in my list, it'll return the 15th element when it hits 0.5 slider value etc etc. The data held in the list comes back like the following:

11/12/2001

This is my code so far:

  1.         // Update is called once per frame
  2.         void Update ()
  3.         {
  4.  
  5.                 sliderElement.value = float.Parse(elapsedString);
  6.         }
  7.  
  8.         void Slider()
  9.         {
  10.                 startTime = new DateTime(startYear, startMonth, startDay);
  11.                 endTime = new DateTime(endYear, endMonth, endDay);
  12.                
  13.                 TimeSpan elapsed = endTime.Subtract(startTime);
  14.                
  15.                 startString = startDay.ToString();
  16.                 elapsedString = elapsed.TotalDays.ToString();
  17.                
  18.  
  19.                 int totalDays = (int)endTime.Subtract(startTime).TotalDays;
  20.                
  21.                 days.Add(startTime);
  22.                
  23.                 for (var i = 1; i < totalDays; i++)
  24.                 {
  25.                         days.Add(startTime.AddDays(i));
  26.                 }
  27.                
  28.                 days.Add(endTime);     
  29.         }

However, when I run the following my slider is permanently stuck at 1 and I can't move it. When I debug out the value, it returns 1 (where I hoped it would return the last date in the list).

Could someone help me out?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Another slider issue
« Reply #1 on: March 21, 2014, 01:13:46 PM »
Overcomplicating it much? :P
  1. int val = Mathf.RoundToInt(Mathf.Lerp(0, 30, slider.value));