- Home /
Button Scroll view original default button becoming clone
ok this will require some explaining. so I'm making a scroll view two in fact how its supposed to work is that when I click on one of the buttons it creates a another button the scrollview on the right, so that works out just fine, however when the left scroll view populates the default button that acts as a base for the others to be created is turned into a clone and as such the first file(button) is unclickable(because it has taken the position of the base).
so I need a way to either
swap the text of the first two buttons(the default and the D:flowers-Daisy) for it work out well or
or prevent the original default from becoming a clone. keep in mind that besides the default one which needs to be their to create the others, the rest of button text comes from a file Directory I have on my computer.
like I said complicated I attached some images of the unity project
if you happen to know anything about the text overlap on the right that's cool to but that my secondary concern.
[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);
}