display list [Solved]

So I have this list that gets new items when I press a button, and when I press another button the list gets displayed, but each time the list gets displayed, you can still see the old list… kinda like this:

adds new item
displays list

  • one item

adds new item
displays list

-one item

-one item
-second item

adds new item
displays list

-one item

-one item
-second item

-one item
-second item
-third item

and so on…
but I want it to like clear the old one and only display the new list

    public void ShowInventory()
    {
        foreach (var name in inventory)
        {
            inventoryText.text += name + "\n\r";
        }
    }

I use a UI text element to display it

1 Like

Use inventoryText.text = “”; as the first line in the function.

1 Like

Thank you! :smile:

1 Like