Cannot implicy convert type string[] to string

Viewed 57

I'm having this problem, I'm getting a "Cannot implicitly convert type string[] to string".

public class InventoryText : MonoBehaviour
{
    PlayerInventory Inventory;

    public Text TextInventory;
    // Start is called before the first frame update
    void Start()
    {
        Inventory = GameObject.Find("Inventory").GetComponent<PlayerInventory>();
    }

    // Update is called once per frame
    void Update()
    {
        TextInventory.text = Inventory.Items;
    }
}
1 Answers

Items is presumably a string[] (an array of strings). You can't just assign it to a string like text. One thing you could do is join them:

TextInventory.text = String.Join(", ", Inventory.Items);
Related