First when i assigned a scroll to a scroll rect it distorted it, and i had to add extra values. THEN when i tried to use it it didnt work and all the values in the scroll script continually get messed up! Help?
[39005-screenshot+(175).png|39005]
I’m afraid that this is expected behavior @awplays49, the ScrollBar doesn’t appear to have a way to set a fixed size for the handle. I thinks it’s a bit rubbish as well.
From a technical point of view there’s no reason for this, the handle shouldn’t have to expand for smaller scroll panels and it should also have a tick to hide the bar if the scroll panel fits inside the scroll rect without overlap.
It’s a flaw and quite a big one from the point of view of scrollbars in general, what if you have a custom sprite that you want to use, expanding will distort it.
I’m considering writing my own but don’t expect anything soon. I’ll update if I get one working.
EDIT
Not without quite a bit of work, I’ve been trying to set the scale of the button with layout elements but there is no max size that I can see. I’m kinda hoping they update the ScrollBar so it has more features, after all it’s early days for the new UI but I suspect that’ll be a while off. I will let you know if I find a way of doing it but not had any good results so far.
EDIT
OK @awplays49 it’s a bit of stupid way to fix it but it works until I get a better way.
Keep your ScrollBar that’s referenced on the ScrollRect but Add Component to it and give it a CanvasGroup.
On the CanvasGroup set Alpha = 0, un-tick Interacable and BlocksRaycast and tick Ignore Parent Group.
You now have an invisible ScrollBar that can’t be affected by clicks, we’re just going use to interface between a Slider and the ScrollRect/ScrollPanel.
Add a Slider to the UI and set whatever images you want for the background, fill area and handle.
Then drag this script onto the Slider:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class FakeScrollBar : MonoBehaviour {
public Scrollbar RealScrollBar;
public void PassThrough(float scrollValue)
{
//Debug.Log (scrollValue);
RealScrollBar.value = scrollValue;
}
}
And drag the invisible ScrollBar onto the empty slot in the script.
Now on the Slider click the + on the OnValueChange and drag the Slider (with the script on it) onto the slot that appears. From the dropdown select FakeScrollBar → PassThrough.
Think you’ll need to have the slider set to BottomToTop for your screen.
EDIT FINAL
OK @awplays49 ignore the last post we don’t need the hidden ScrollBar we can just make a Slider act like a ScrollBar. So delete the ScrollBar and put a Slider in it’s place then add this script to the Slider:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class FakeScrollBar : MonoBehaviour {
public ScrollRect MyScrollRect;
public void PassThrough(float scrollValue)
{
MyScrollRect.verticalNormalizedPosition = scrollValue;
}
}
Drag the ScrollRect panel onto the empty slot, oh and if you want horizontal movement then change verticalNormalizedPosition to horizontalNormalizedPosition and make the Slider a LeftToRight or RightToLeft one.
As for your question about why ScrollBars re-size when you hit play, that’s because when you’re not running the game it’s not calculating the size of the scrollRect/scrollPanel so it lets you set the handle to be any size. When you hit play it starts calculating the size and scales the handle accordingly.
Sliders don’t scale the size of the handle so by passing the Slider value to the ScrollRect we can simulate a ScrollBar without scaling the handle size.
This is an example project using SlidersForScrollbars:
“the slider is NOT supposed to look like that”. Okay, but what is wrong with it? Are you referring to how its rounded corners are stretched? If so, the problem comes from the Image Type of the handle Image.
Currently, the Image component of the handle has its Image Type set to “Simple”. It should be “Sliced”. For “Sliced” to work, the borders of your sprite must be properly set. You can do that with the Sprite Editor as explained there: UI Image - Unity Official Tutorials - YouTube .
Result: http://i.imgur.com/9q68Bab.png