- Home /
I found my own very easy solution
Horizontal Layout Group making a Scroll Rect's Content rect width to be negative
For my inventory system, when you open the inventory there are 2 panels, one for your inventory and one for the chest/container you are looking into. So I have a horizontal layout group to split them up evenly over the screen like this:
I use a Scroll Rect to contain the slots of the inventory, and I get the width of the Scroll Rect's "Content" object to correctly position the slots.
Without using the Horizontal Layout Group it works fine, but when I use it,
content.GetComponent<RectTransform>().rect.width
returns -120, even though I can clearly see (while selecting it in the editor during playtime) that it has a large positive width.
How can I get the width of the Content object's rect since it's being stretched?
Answer by jcv8000 · Jun 05, 2016 at 11:55 PM
I really need to get to know the UI system better...
In the end I made 2 RectTransforms (left & right, these contain the inventory and container panels) and made them stretch to the whole screen, and set their anchor min/max's X to 0.5, which is 1/2 of the screen always.
Follow this Question
Related Questions
Fill empty space in parent in UI Layout 1 Answer
How to change the Top and Bottom (rect.yMin and yMax) properties of a rectTransform, in a script? 2 Answers
Changing Rect Position in code causes object to disappear? (C#) 0 Answers
Retreive the Width Delta of a ContentSizeFitter game object 0 Answers
How to Save Property Values of a Component on a Scriptable Object? 1 Answer