What I want is, when I click on the button, the image and it’s child object (text component) will change to a next image sprite and text component.
I tried to do that with switch statement but I’m unsure that this is the right solution and I also managed to do that for the text only, but not the image. And I’m also linking the buttons child object instead which is not ideal
Here’s what I’ve done:
public Button nextButton;
private string currentText = "Text1";
void Start()
{
SetText(currentText);
nextButton.onClick.AddListener(MyButtonClick);
}
void MyButtonClick()
{
switch (currentText)
{
case "Text1":
currentText = "Text2";
SetText(currentText);
break;
case "Text2":
currentText = "Text3";
SetText(currentText);
break;
case "Text3":
currentText = "Play Game";
SetText(currentText);
break;
}
}
void SetText(string text)
{
nextButton.transform.GetChild(0).GetComponent< TMPro.TextMeshProUGUI>().text = text;
}
Thank you in advance!