Custom class and hashtable

I've been trying to set up my own class, GeneralItem, and store these in a Hashtable. The scripts are as follows:

GeneralItem class

using UnityEngine;
using System.Collections;

public class GeneralItem : Object {

    public string itemName;
    public int sellPrice;
    public Texture icon;
    public bool isStackable;
    public string description;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
}

ItemList script

using UnityEngine;
using System.Collections;

public class ItemList : MonoBehaviour {

    public GeneralItem Turnip, Potato;
    private int amountOfItems;
    public GeneralItem[] itemArray;
    public Hashtable itemList = new Hashtable();
    //Hashtable: key is what you search, value is what is returned

    // Use this for initialization
    void Awake () {
        createItemList();
    }

    // Update is called once per frame
    void Update () {

    }

    private void createItemList() {

        Turnip = new GeneralItem();
        Turnip.itemName = "Turnip";
        Turnip.sellPrice = 50;
        Turnip.icon = Resources.Load("icons/ItemIcon") as Texture;
        Turnip.isStackable = true;
        Turnip.description = "Just a turnip.";
        itemList.Add(Turnip.itemName, Turnip);

        Potato = new GeneralItem();
        Potato.itemName = "Potato";
        Potato.sellPrice = 60;
        Potato.icon = Resources.Load("icons/PotatoIcon") as Texture;
        Potato.isStackable = true;
        Potato.description = "Only a potato.";
        itemList.Add(Potato.itemName, Potato);
    }

    public GeneralItem FindItemByName(string itemName) {
        if (itemList.ContainsKey(itemName)) {
            GeneralItem newItem;
            newItem = itemList["Turnip"] as GeneralItem;
            return(newItem);
        } else {
            return null;
        }
    }

}

However, when trying to see what value comes with "Turnip" in the hashtable, I get 'GeneralItem' instead of 'Turnip'. Also, when I try to assign a GeneralItem via the interface of Unity, neither Turnip nor Potato shows up in the list of usable GeneralItems.

My question is, how can I make sure 'Turnip' is retrieved in the hashtable instead of 'GeneralItem'?

A few suggestions and observations ...

  • when you say you "get 'GeneralItem'", do you mean that's what shows up in the Inspector? or are you printing the value? I suspect this is simply the default ToString method showing you the name of the type
  • if you want your items to show in the Inspector, you need to add the System.Serializable attribute to your class
  • you still won't see a drop down menu with Potato and Turnip, but you could add a custom editor that uses your hash table to do so
  • you might also add a ToString override method to GeneralItem to give you more information about the particular item
  • I suggest you use System.Collections.Generic, and then you can use Dictionary instead of simply Hashtable -- it gives you more type safety and ease of use, no need to typecast values retrieved from the dictionary
  • you probably don't need to derive from Object, just declare your GeneralItem class with no base class
  • GeneralItem.Start and GeneralItem.Update will never be called, since GeneralItem is not a component (it doesn't derive from MonoBehaviour) (I wish the Unity editor had right-click > Create Script and Create Behaviour as different menu items, with different starting code templates :-)