0

I have a ScrollRect to which I add content to. When it reaches the point where the content is longer than the ScrollRect (ie when the ScrollBar's value changes from 0), I want the ScrollRect to scroll all the way down (I do this by tweening the ScrollBar's value until it reaches 0). However, my problem is that I can't figure out how to do this smoothly over time.

Here's my code snippet:

        public void Update() {
        if (scrollbar.size < 1 || scrollbar.value > 0) {
            LeanTween.value(scrollbar.value, 0, duration).setOnUpdate((float val) => {

                if (scrollbar.value == 0) {
                    LeanTween.cancel(this.gameObject);

                } else {
                    scrollbar.value = val / scrollAdjustment;
                }

            });

        }
    }

I tried using "Time.deltaTime" and "Time.time" in place of duration and it did not seem to matter. Here's a gif of what happens:

enter image description here

(In this example, I used "duration" that had the value of 5 (the idea was to have the transition take 5 seconds) and "scrollAdjustment" was 50 but it did not seem to matter what I set either of these values to.

You can see it instantly snaps to the bottom. I'd like this to be a smooth transition. Any help is appreciated!


My settings:

enter image description here

enter image description here

Then here is me scrolling with my mouse wheel while the autoscroll feature is turned off (because I'm using Rewired, I am intercepting an input called "ZoomIn" and "ZoomOut" and add "0.01f * scrollSpeed" (where scrollSpeed is 15 in this case):

enter image description here

1 Answers1

0

You shouldn't need to add any additional code to make the scroll bar function as the way you want it to. Try deactivating your script and mess with your scroll bar. Make sure you have your Number Of Steps On Your Scrollbar Component as 0 to make it smooth. If it's still not working, send some screenshots of your scroll gameobject to see if the rect is the problem or something else.

  • Thank you! I have checked and it was set to 10. I have now changed it to zero but unfortunately there is no change. I added my settings to the OP for easier reading. Let me know if I should attach any other info, and thank you for your time. – The Embraced One Jan 27 '23 at 22:16