1
\$\begingroup\$

I am using the Unity Slider component. I have a custom background and custom knob. But whenever I move the slider, my knob's size becomes distorted. It is 100x100 pixels, and when I set it to its native size, it does so. But I soon as I move the slider, it cuts its height in half. How can I prevent this from happening?

\$\endgroup\$
2
\$\begingroup\$

3 ways. 1) should work for all cases.

1) Parent the handle object to some empty and assign this object slider handle rect. Also, change the Anchor Preset to not stretched in Handle object. Thus slider will change Anchor Preset of GameObject, but Handle has no stretched, so it will not be changed.

Parenting Example Anchor Presets

2) There is a Preserve Aspect toggle in Image component, this may not work for you if you want your handle image to be another aspect.

Image Component

3) Try scaling it in Scale, not changing its width or height.

\$\endgroup\$
  • \$\begingroup\$ Is there a way to preserve the aspect ratio AND allow it to resize with the rest of the objects on the panel? As it is, when the window grows to 1080p, the rest of the images resize but the handles will not, making them very hard to see. \$\endgroup\$ – Dev Aug 12 '18 at 9:47
  • \$\begingroup\$ @Dev there is a UI component that preserves the aspect ratio. \$\endgroup\$ – Candid Moon _Max_ Aug 12 '18 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.