The following code compiled but the lines that called SetActive on the button or input field did not do anything nor did the lines that set the text for the button.
After trying for some time to find out what I was doing wrong I noticed that I was not using the text mesh pro version of the button. So I changed it not expecting it to fix my problem. But after I changed the following type of line:
theButton.GetComponentInChildren().text = “Draw”;
to:
theButton.GetComponentInChildren().text = “Draw”;
Things still didn’t work. But after I changed it to
theButton.GetComponentInChildren().text = “Draw”;
Both the changing of the text worked and the SetActive calls worked.
I imagine that there must not actually be a Text component on the standard button component, and there isn’t a TextMeshPro component on the Text Mesh Pro version of the button, but there is a TextMeshProUGUI component, and this is why correcting this would fix the code to work to change the text on the TextMeshPro buttons. (What component should be used to change the text on the standard button?)
So this is actually the biggest question I want answered. WHY WOULD CHANGING THIS MAKE THE SETACTIVE CALLS WORK? I’m at a loss.
This is the original code that did not work:
void Awake()
{
textOut("How many 1's?");
userInput.keyboardType = TouchScreenKeyboardType.NumberPad;
userInput.contentType = TMP_InputField.ContentType.IntegerNumber;
userInput.enabled = true;
theButton.GetComponentInChildren<Text>().text = "Draw";
userInput.gameObject.SetActive(true);
theButton.gameObject.SetActive(false);
theButton.enabled = false;
}
public void actOnUserInput()
{
switch(UserInputHandler)
{
default:
case UserInputStep.numberOfOnes:
ones = int.Parse(userInput.text);
textOut("How many 2's?");
UserInputHandler = UserInputStep.numberOfTwos;
break;
case UserInputStep.numberOfTwos:
twos = int.Parse(userInput.text);
if(twos > 4)
{
textOut("Value must be less than 5!");
}
else
{
textOut("How many 3's?");
UserInputHandler = UserInputStep.numberOfThrees;
}
break;
case UserInputStep.numberOfThrees:
threes = int.Parse(userInput.text);
Shuffle();
textOut("Ready");
userInput.enabled = false;
UserInputHandler = UserInputStep.numberOfOnes;
userInput.gameObject.SetActive(false);
theButton.enabled = true;
buttonHandler = buttonFunction.draw;
theButton.gameObject.SetActive(true);
break;
}
}
public void actOnButtonPress()
{
switch (buttonHandler)
{
case buttonFunction.draw:
theButton.enabled = true;
if (stack[0] != 0)
{
textOut("this should be replaced");
textOut(stack[0].ToString());
for (int RiseUp = 0; RiseUp < 21; RiseUp++)
{
stack[RiseUp] = stack[RiseUp + 1];
}
stack[21] = 0;
}
else
{
textOut("Blip stack empty");
buttonHandler = buttonFunction.restart;
theButton.GetComponentInChildren<Text>().text = "Reset";
}
break;
default:
case buttonFunction.restart:
textOut("How Many 1's?");
theButton.enabled = false;
userInput.enabled = true;
userInput.gameObject.SetActive(true);
UserInputHandler = UserInputStep.numberOfOnes;
buttonHandler = buttonFunction.draw;
theButton.GetComponentInChildren<Text>().text = "Draw";
theButton.gameObject.SetActive(false);
break;
}
}
This is the code that does work:
void Awake()
{
textOut("How many 1's?");
userInput.text = "";
userInput.keyboardType = TouchScreenKeyboardType.NumberPad;
userInput.contentType = TMP_InputField.ContentType.IntegerNumber;
userInput.enabled = true;
theButton.GetComponentInChildren<TextMeshPro>().text = "Draw";
userInput.gameObject.SetActive(true);
theButton.gameObject.SetActive(false);
theButton.enabled = false;
}
public void actOnUserInput()
{
switch(UserInputHandler)
{
default:
case UserInputStep.numberOfOnes:
ones = int.Parse(userInput.text);
textOut("How many 2's?");
userInput.text = "";
UserInputHandler = UserInputStep.numberOfTwos;
break;
case UserInputStep.numberOfTwos:
twos = int.Parse(userInput.text);
if(twos > 4)
{
textOut("Value must be less than 5!");
}
else
{
textOut("How many 3's?");
userInput.text = "";
UserInputHandler = UserInputStep.numberOfThrees;
}
break;
case UserInputStep.numberOfThrees:
threes = int.Parse(userInput.text);
Shuffle();
userInput.text = "";
textOut("Ready");
userInput.enabled = false;
UserInputHandler = UserInputStep.numberOfOnes;
userInput.gameObject.SetActive(false);
theButton.enabled = true;
buttonHandler = buttonFunction.draw;
theButton.gameObject.SetActive(true);
break;
}
}
public void actOnButtonPress()
{
if(displayText.text == "Ready")
{
textOut("");
}
switch (buttonHandler)
{
case buttonFunction.draw:
theButton.enabled = true;
if (stack[0] != 0)
{
textOut(displayText.text + stack[0].ToString() + "\n");
for (int RiseUp = 0; RiseUp < 21; RiseUp++)
{
stack[RiseUp] = stack[RiseUp + 1];
}
stack[21] = 0;
}
else
{
textOut(displayText.text + "Blip stack empty");
buttonHandler = buttonFunction.restart;
theButton.GetComponentInChildren<TextMeshPro>().text = "Reset";
}
break;
default:
case buttonFunction.restart:
textOut("How Many 1's?");
theButton.enabled = false;
userInput.enabled = true;
userInput.gameObject.SetActive(true);
UserInputHandler = UserInputStep.numberOfOnes;
buttonHandler = buttonFunction.draw;
theButton.GetComponentInChildren<TextMeshPro>().text = "Draw";
theButton.gameObject.SetActive(false);
break;
}
}