Clicking a button will display that buttons text in a seperate text-field

Hi guys, in case the title isn’t clear, What I’m trying to do is this:

When I click on a button, the ChangeLabelToButtonsText() Method is called. Within the method, I want the labelObject’s text to change to whatever the text on the button is.

Below is what I have but it’s not working.

public GameObject labelObject; //labelObject is the GUI Text GameObject

void ChangeLabelToButtonsText()
        labelObject.GetComponent<Text>().text = this.GetComponent<Text>().text;

Thanks guys,


The Text component is actually on a child of the Button gameobject rather than the gameobject itself, so you’ll need to find the component using something like:

labelObject.GetComponent<Text>().text = this.GetComponentInChildren<Text>().text;