Search Unity

Question Dropdown scrollbar sound.

Discussion in 'UGUI & TextMesh Pro' started by MusicW0lf, Oct 17, 2022.

  1. MusicW0lf

    MusicW0lf

    Joined:
    Feb 27, 2022
    Posts:
    5
    So scrollbar can only have values from 0 to 1 and what I trying to do is add sound whanever scroolbar moves, the problem is sound can play several times before scrollbar even move when pulling it slowly. I undestand that it's because value changes by small amount and because I use onvaluechanged event, but when I try to check value in inspector it always show 0.
    My question is: How can I play sound with scrollbar only when it visually moves?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Every frame that there is a movement there will be a call to onValueChanged.

    Every time you start a sound generally it starts over at the beginning.

    Let's say there is motion on frames 0 and 1 but not on frame 2 or 3, then again it moves on 4, 5, 6, but not 7, then 8, but not 9, etc.

    Keep in mind each frame is nominally 1/60th of a second, so for 1/30th of a second there is motion, then 1/30th of a second there is none, then back to motion.

    What exactly is your intention here?
     
  3. MusicW0lf

    MusicW0lf

    Joined:
    Feb 27, 2022
    Posts:
    5
    I want sound to play only when scrollbar VISUALLY changed, in my case it's ~13 positions. Right now it changes everytime I move mouse when holding it.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    You would need to compute that "~13 positions" as a function of overall scrollbar size, scale of the items inside relative to the viewable rectangle, and likely also take into account the Canvas Scaler settings and possibly even the Canvas render mode.

    Then just don't play it until enough motion occurs in the same direction to meet your requirements!

    Alternately put a ghost zero sized GameObject in the scrolling stuff and have it determined "did I move far enough to be visible?"

    Luckily the entire UI system is open source so you can see how the different parts work here:

    https://github.com/Unity-Technologies/uGUI
     
  5. MusicW0lf

    MusicW0lf

    Joined:
    Feb 27, 2022
    Posts:
    5
    Thanks for reply, I'll try this and hope it works.