Array on buttons. Then change the text.

Hello guys, I am making a very simple thing but I just couldnt get it work.

So what I wanna do is. 3 buttons . A, B and C on GUI. Using TextMeshProUGUI.

example.
When clicked A, the text in button A’ will change.

It’s like checking for an item’s information.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class ItemInfo : MonoBehaviour
{
    // Start is called before the first frame update
    TextMeshProUGUI text;
    public GameObject[] iteminfo; // Button array
    int i;
    void Start()
    {
        text = gameObject.GetComponentInChildren<TextMeshProUGUI>();
    }

    // Update is called once per frame
    void Update()
    {
       
    }
    public void showInfo()
    {
        text.text = iteminfo[i].name; // show item info.
    }
}

Much thanks!

This copies the GameObject name field into your text.

Remember buttons don’t have any text in them. The text is a sub-object below the button, traditionally.

Draw some data flow diagrams for yourself: draw 3 buttons, draw what goes into each one, and draw the arrow which is the “action” to do it, and this should reveal what steps you’re missing. You can probably use the same script in multiple places, just connecting different things to different parts, but you have to understand what you’re doing first.