Greetings, I am having some difficulty getting the hang of creating a UI from a script. I have a sidebar and I’d like to create a square object in the sidebar that has the exact same width as the sidebar. I thought this would be the solution:
float widthOfSideBar = sideBar.GetComponent<RectTransform>().rect.width;
gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(widthOfSideBar, widthOfSideBar);
However it ends up being about 80% of the size at runtime. What is my error?