I’m having a bit of trouble with the UI system. Never quite understood it. Can someone explain how I stop this from happening:
This is how it looks in the editor and it’s also how I want it to look:
Now this is what it looks like in full screen 1920x1080:
This is what the button object looks like in the editor (while the game is not running):
This is the code for positioning the buttons:
void createButton(string id, string t, int i)
{
// Create a Button object
if (buttonGameObject != null)
{
scrollPanel.GetComponent<Image>().enabled = true;
scrollObject.GetComponent<RectTransform>().sizeDelta = new Vector2(scrollObject.GetComponent<RectTransform>().rect.width, d.GetNode(DialogueID.ToString()).options.Length * 85);
scrollPanel.GetComponent<ScrollRect>().normalizedPosition = new Vector2(0, 1);
GameObject b = Instantiate(buttonGameObject, new Vector3(10, 160 - (60 * buttonID)), Quaternion.identity);
b.transform.SetParent(scrollObject.GetComponent<RectTransform>().transform);
b.GetComponentInChildren<Text>().text = "" + t;
UnityEngine.Events.UnityAction action1 = () => { this.onButtonClicked(id, i); };
b.GetComponent<Button>().onClick.AddListener(action1);
buttonID++;
}
}
How do I get it to look the same no matter the resolution?