- Home /
Question by
cornyb1g · Oct 16, 2016 at 11:54 AM ·
buttonscalecreatedynamically
Scaling dynamic created buttons
Hi,
I'm trying to create a dynamic menu in unity but having a problem where my buttons that i create don't scale correctly. I've put Vertical layout group to my panel but it doesn't trigger.
Here's a picture:
The test buttons are the one i create dynamically, i want it to look like the "Previous" button.
Here's my code where i create the buttons.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class menu : MonoBehaviour {
[SerializeField] GameObject buttonPrefab;
[SerializeField] Transform menupanel;
void Start () {
for (int i = 0; i < 6; i++) {
GameObject button = (GameObject) Instantiate (buttonPrefab);
button.GetComponentInChildren<Text>().text = "Test";
button.transform.localScale = new Vector3 (1.0f, 1.0f, 1.0f);
button.transform.parent = menupanel;
}
}
// Update is called once per frame
void Update () {
}
}
screenshot-2016-10-16-130710.png
(326.5 kB)
Comment
If you are using a Layout group, you probably don't want 16; on 17 try the transform.SetParent(menupanel, false);