Instantiate gui.Text issue


I am facing an issue, which i have been trying to solve for the past few hours, but no luck. My problem:

I have an interface with 5 buttons, each with their unique "id" set, which retrieves information from an data file and shows the data on the Gui.Text prefab i have setup.

Prefab: a guitext component named itemText

What it doesn:

It creates a set of buttons made from the arrayList and shows them correctly on the GUI - clicking one of those buttons, retrieves the information and displays it correctly. Although when i click another button in the same session, it seems it has duplicated the info from the first button, even though the data and the button "id" are unique!

What i'd like it to do is that when you click on another button, the "previous" object is overwritten, is there any way todo this ?

I tried destroying the prefab before initializing / on startup and when there is already some "text" retrieved, no luck on that :(

This is the code i have (some methods are removed)

public class ItemSelection : MonoBehaviour {

float ScreenWidth;
float ScreenHeight;

public string item_name;
public GameObject itemText;

IEnumerator getItems(int id){
    // www classs
    data = update_get.text;

void ShowInfo(int item_id){
    GameObject itemName_GUI = Instantiate(itemText) as GameObject;

    itemName_GUI.guiText.text = item_name;
    itemName_GUI.guiText.fontSize = 14;
    itemName_GUI.guiText.pixelOffset = new Vector2(-250, 200);

void OnGUI() {
    ScreenWidth = (Screen.width/2);
    ScreenHeight = (Screen.height/2);
    int i;

    ArrayList arrayItems = new ArrayList();

    int buttonHeight  = -375;

    for (i = 0; i < arrayItems.Count; i++){
        buttonHeight  = buttonHeight+60;
        string name = arrayItems *as string;*
 *if (GUI.Button( new Rect(ScreenWidth-500,ScreenHeight-buttonHeight,250,50), name)){*
 *isEmpty = 0;*

So, what is happening is what you wrote. You are creating a new object every time with this line

GameObject itemName_GUI = Instantiate(itemText) as GameObject;

So what you have to use is create just once that gameObject, and then only update this

itemName_GUI.guiText.text = item_name;

Then the text will change.

My suggestion is:

1 Do this at the very begining

GameObject itemName_GUI = Instantiate(itemText) as GameObject;