Setting choice text directly

You can use the following

foreach (string choiceText in m_PlayerConversant.GetChoices())
{
    GameObject choiceButton = Instantiate(m_ChoicePrefab, m_ChoiceRoot);
    choiceButton.GetComponentInChildren<TextMeshProUGUI>().text = choiceText;
}

instead of

foreach (string choiceText in m_PlayerConversant.GetChoices())
{
    GameObject choiceInstance = Instantiate(m_ChoicePrefab, m_ChoiceRoot);
    var textComp = choiceInstance .GetComponentInChildren<TextMeshProUGUI>().text = choiceText;
    textComp.text = choiceText;
}

It only saves one line but it’s still a bit shorter :slight_smile: Hope it helps.

1 Like

Shorter is always better if it works as efficiently!

Privacy & Terms