I have a UI text that I would like to change with a button click. How do I dod that with something like this?
//UI Text Reference
public Text MessageCentreText;
public void GoScanner()
{
StartCoroutine (LoadS1());
//Send to Sending script for message out to Arduino
Sending.sendRed2 ();
}
IEnumerator LoadS1(){
yield return new WaitForSeconds(3.5f); // wait time
}
The reference to change is “.text”. For example:
MessageCentreText.text = "this is my text";
Of course, that’s only half of it. To make a button do that, you’d need to put it in a script. Something like:
public void ChangeText(){
MessageCentreText.text = "this is my text";
}
Then, you would need your button to call that script. In the button setings, there is an “OnClick” section. You need to drag whatever has this script on it in there and assign the button to call ChangeText.