Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Adeel on April 14, 2014, 04:04:45 AM

Title: Scroll bar help
Post by: Adeel on April 14, 2014, 04:04:45 AM
Hi guys,

I'm just after a bit of help with making a music scroll bar with ngui I have a 16 minute audio track and I am using a scroll bar to try and move it to the right point in the audio. I have it working in that it moves along with the audio however every time I move the scroll bar it always restarts the track from the beginning.
Heres the stuff I have so far:
  1. public UIScrollBar scrollBar;
  2.  
  3.         public AudioSource mainMusic;
  4.  
  5.         public float newMusicTime;
  6.  
  7.         void Update()
  8.         {
  9.                 if(AudioControllers.musicPlaying == true && AudioControllers.pauseMusic == false)
  10.                 {
  11.                         scrollBar.value += 1 / mainMusic.clip.length * Time.deltaTime;
  12.  
  13.                         if(Input.GetMouseButtonUp(0))
  14.                         {
  15.                                 mainMusic.time = scrollBar.value;
  16.  
  17.                         }
  18.                 }
  19.         }

I feel that I am close but its just not working any help would be much appreciated.

Thanks.
Title: Re: Scroll bar help
Post by: rain on April 15, 2014, 08:16:41 AM
If i'm not mistaken, the Scroll Bar's value only has a range from 0 to 1, so you're constantly setting the time on the audio source to something like the first 0-1 seconds.

If my above statement is right, then it should be something like this:
  1. public UIScrollBar scrollBar;
  2.  
  3.     public AudioSource mainMusic;
  4.  
  5.     public float newMusicTime;
  6.  
  7.     void Update()
  8.     {
  9.         if(AudioControllers.musicPlaying == true && AudioControllers.pauseMusic == false)
  10.         {
  11.             scrollBar.value += 1 / mainMusic.clip.length * Time.deltaTime;
  12.  
  13.             if(Input.GetMouseButtonUp(0))
  14.             {
  15.                 // so for example your scrollbar is at the half -> its .value is 0.5f
  16.                 // then you'd set the time to 0.5 * CLIPLENGTH
  17.                 mainMusic.time = scrollBar.value * mainMusic.clip.length;
  18.             }
  19.         }
  20.     }
  21.  
Title: Re: Scroll bar help
Post by: ArenMook on April 15, 2014, 09:51:36 AM
Yes that's right, scroll bar's value is always 0 to 1.
Title: Re: Scroll bar help
Post by: Adeel on April 16, 2014, 01:51:16 AM
Thanks for the reply and sorry for the lateness of mine I've not had  a good Internet connection for the last couple of days!

Yeah the scroll bar value is 0-1 your suggestions looks about right I'll give it a go and reply when I've tested it on Thursday. Thanks again.
Title: Re: Scroll bar help
Post by: Adeel on April 17, 2014, 03:34:22 AM
Thanks for your help rain just tested it and it works!