C# Dictionary değişken bulunamadı hatası veriyor

Mucosoft

Megapat
Katılım
5 Mart 2014
Mesajlar
5.514
Makaleler
12
Çözümler
41
Fonksiyon Kitaplığı
C#:
    static Dictionary<string, int> Items = new Dictionary<string, int>();
    static string[] ItemList = { "Iron" };
    static string SelectedItem = "Iron";
    void Start()
    {
        foreach (var Item in ItemList)
        {
            Items.Add(Item, 0);
        }
    }
    public static void AddItem(string ItemName)
    {
        if (Items.ContainsKey(ItemName))
        {
            int Value = Items["ItemName"];
            Items.Remove(ItemName);
            Value++;
            Items.Add(ItemName, Value);
        }
    }
    public static int GetItemAmount(string ItemName)
    {
        return Items[ItemName];
    }
Nesne
C#:
    void Start()
    {
        FactoryGameInventory.AddItem("Iron");
        FactoryGameInventory.AddItem("Iron");
        Debug.Log(FactoryGameInventory.GetItemAmount("Iron").ToString());
    }
Hata
KeyNotFoundException: The given key was not present in the dictionary.

Nasıl çözerim?
 

Yeni konular

Geri
Yukarı