I like to position RectTransform of UI Elements with Custom Anchors set to its Corners in the script.
I am doing this with changing the Orientation of the Screen. I have tried anchoredPosition, but not effective.
Also tried localTranform. When i try to position with these options, UI Element moves to the desired position but the Anchors are staying at the Original position. I need the Anchors also to be moved to make the UI Scale to any screen resolution. I am totally stuck with this. Kindly help me in this concern as soon as possible.
Here are the pictures that i like to get the UI to be. You can see the Anchors of all the UI elements is set to its own corners. I cant use any auto Layouts because the original UI is much more complicated.
I`ll just upwote this. right now I am trying to do the same thing to switch screen layout when I switch between portrait or landscape orientation.
There are these properties in RectTransformClass: anchorMax and anchorMin, which are Vector2. I think, bu using them you can change anchor positions…
Have you found any solution to this? How are you checking when you have to change from Landscape to Portrait and back?
Wow! huge thank you for such a fast answer! I`ll check out your UGUI Tools.
I think I have figured something out. I have found this thread: UI rotation - Unity Engine - Unity Discussions
There is a post there that says:
Yup. You can programatically alter all the properties of a RectTransform, for example:
What I did was: First, I set the position of the anchors by setting anchorMin and anchorMax. both ara Vector2 and take relative positions in canvas (values between 0 and 1), right after I did this, I set anchoredPosition to Vector2.zero. This just fits your rect between the anchors. These settings seem to work perfect for setting position of custom anchored trasforms with anchors in corners.
sizeDelta adds padding on the sides, might also be useful.
I`m curious if the author of this post came up with a solution to check the screen orientation.