'How to get child text text via script on button?

I have a button with a text child object. I have a script on this button. How to get the text of the button's child object through this script?

enter image description here

Here is the script hanging on the button.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class monumentButtonAppy : MonoBehaviour
{   
    public void ButtonPressed()
    {
        // DataHolders.Monument
        SceneManager.LoadScene(3);
    }
}

The received text from the button, I need to apply it to the variable "DataHolders.Monument"



Solution 1:[1]

This could be another way if you have script on button GameObject

button.gameObject.transform.GetChild(textIndex /*Usually it's 0*/).GetComponent<Text>().text="Hello World"

Solution 2:[2]

button.GetComponentInChildren(); Or make a public Text text,and drag your text to it in unity Editor.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HTugsadK
Solution 2 samke