- Home /
Button as a child of a button
I've been using Unity in about five months now, and I've been working on a project for last few weeks, and it's almost finished. And I want to implement shop UI for my project. And when I attached a button as a child of my shop UI and add a listener to it from a script. it did work. But when I clicked on a parent button the child button is also clicked. So I want my parent button just to change a color for my model as preview, and the child button to buy/set the color if already owned. So the question is. Is there something wrong with my design or it was my script? or I just can't have a button as a child of another button? Thanks before, any help would be appreciated.
Here is my code to add a on click listeners
void SetShopButtons()
{
int i = 0;
foreach (Transform t in colorViewport)
{
int currentIndex = i;
Button b1 = t.GetComponent<Button>();
Button b2 = b1.GetComponentInChildren<Button>();
Text buySetText = b2.GetComponentInChildren<Text>();
b1.onClick.AddListener(() => OnColorSelect(currentIndex, buySetText));
b2.onClick.AddListener(() => OnColorBuySet());
if (SaveManager.Instance.OwnedColorCheck(i))
buySetText.text = "Owned";
else if (i == activeColorIndex)
buySetText.text = "Current";
else
buySetText.text = colorPrice[i].ToString();
i++;
}
}
Your answer
Follow this Question
Related Questions
Touch Input with Event Trigger. How to handle with it properly. 0 Answers
How to scale different GUI objects to fit screen size ANDROID 1 Answer
Disable/enable local notifications on Android and iOS 0 Answers
System.Diagnostics.Process on iOs and Android 1 Answer
Scriptable object doesn't load in the build of the project 1 Answer