- Home /
Question by
Knightling23 · May 12 at 07:14 PM ·
c#uibutton
scrollview buttons are overlapping
when I press one of the buttons it creates another button on the right however they are overlapping one another thus causing an issue. Any ideas??
[SerializeField] private GameObject leftButtonTemplate;
[SerializeField] private GameObject rightButtonTemplate;
[SerializeField] List<GameObject> leftButtons = new List<GameObject>();
[SerializeField] List<GameObject> rightButtons = new List<GameObject>();
public void PopulateLeftSelection(string[] filesToShow)
{
foreach (string file in filesToShow)//goes through each file
{
GameObject buttonObj = Instantiate(leftButtonTemplate);
Button button = buttonObj.GetComponent<Button>();
leftButtonTemplate.SetActive(true);
leftButtonTemplate.GetComponent<ButtonListButton>().slider = this;
leftButtonTemplate.GetComponent<ButtonListButton>().setText(file);// puts text on buttons
button.onClick.AddListener(delegate { buttonObj.GetComponent<ButtonListButton>().SelectFromLeft(); });
buttonObj.transform.SetParent(leftButtonTemplate.transform.parent, false);
leftButtons.Add(buttonObj);
}
}
public void PopulateRightSelection(string clicked) {
GameObject buttonObj = Instantiate(rightButtonTemplate);
Button button = buttonObj.GetComponent<Button>();
rightButtonTemplate.SetActive(true);
rightButtonTemplate.GetComponent<ButtonListButton>().setText(clicked);
buttonObj.transform.SetParent(rightButtonTemplate.transform.parent, false);
rightButtons.Add(buttonObj);
}
Comment