using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]  // Allows the script to run in the editor
[RequireComponent(typeof(Button))]  // Ensure the GameObject has a Button component
public class ButtonTextUpdater : MonoBehaviour
{
    public Button myButton;  // Reference to the Button component
    public string buttonText = "Default Text";  // Default button text

    // Called whenever a value is changed in the Inspector
    void OnValidate()
    {
        // Automatically assign the Button component if not set
        if (myButton == null)
        {
            myButton = GetComponent<Button>();
        }

        // Update the button text if the Button component is available
        if (myButton != null)
        {
            // Update the button text without having to press Play
            myButton.GetComponentInChildren<Text>().text = buttonText;
        }
    }
}