- Home /
[4.6 2D] Making UI image stick to the side
Hello, I have a simple scene, in it is a simple initial design of having a sidebar with some options(Mute music, mute effects, main menu) on it, but I'm facing a problem when placing it to the side, I try and place the anchors(I frankly don't know much on how they work, but I followed some tips I read and so far they work), everything looks fine in the editor view, but in the game view when maximizing the sidebar moves a bit to the center, making it floating instead of sticking to the side.
Pictures:
1) how I want it to be(Edit view):
2) How it looks in the game view when maximized or it has a high enough resolution:
You can notice it slightly floating to the left, now that might be minor, but it irritates me, it's an initial design with nothing final, but I would like to solve the problem with your generous help, simply knowing how to make it snap to the sides if that's the appropriate word for what I want to do.
Thank you.
Answer by fffMalzbier · Mar 13, 2015 at 11:29 AM
You can set your anchor to middle right. That should all ways have a fixed position to the vertical middle on the right side. Setting the pivot of you element to 1 could help too. I can recommend the UI Rect Transform Tutorial for good overview over the Anchor. http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform
Thank you, that works in keeping the image stuck to the side, but it makes the image small in comparison to the resolution when it increases, that's why I stretched the anchors around the image borders, so that it maintains the size at all resolutions. Is there a way I can anchor it to middle right while still having the size adjustable?
Thank you very very much for the answer!
If you like your whole gui scale to the different resolutions you should take a look at the "Canvas Scaler" component on your canvas. You can set it to "Scale with Screen Size".