How to create an 'Item' subclass

Hi,

I recently received some great help with a question about subclasses and my approach to various item types.

I am now struggling with creating my items - please see below example:

public Item(string name, int cost, string type, string desc){
    _Name = name;
    _Cost = cost;
    _Type = type;
    _Desc = desc;
}

The above is in the Item class (Item.cs) and defines an Item, so to create one I use: new Item(“Item”,100,“Consumable”,“This is an Item”)


public class ArmourUpgrade : Item {
public ArmourUpgrade(){
		_UpgradeValue = 0;
	}
}

I then have this in the ArmourUpgrade class (ArmourUpgrade.cs)…how do I create an ArmourUpgrade in the same way as above?

I’m sure its a simple answer, but I just can’t see it.

Thanks

EDIT:

Update to the question above…

public ArmourUpgrade(string name, int cost, string type, string desc,int UpgVal){
		Name = name;
		Cost = cost;
		Type = type;
		Desc = desc;
		UpgradeValue = UpgVal;
	}

The above code works, so from my Shop script I call ArmourUpgrade(“Upgrade v1”,5,“Upgrade”,“This is Upgrade v1”,“10”), but as al Items have a name, cost, type and desc, does this need to be included in the ArmourUpgrade constructor?

Thanks again.

This helps explain inheritance and constructors
http://unity3d.com/learn/tutorials/modules/intermediate/scripting/inheritance

A little tip I learned in college:

Sit down and write out what each item is, their attributes and everything else. When done, take that information and look for common things, like “Name” or “Price”, make this it’s own class. You then inherit this and start the granulate the concepts down. Here is an example that might help

public class GameItem
{

    public string Name { get; set; }

    public int Cost { get; set; }

    public GameItem(string name, int cost)
    {
        Name = name;
        Cost = cost;
    }

}

public class Weildable : GameItem
{

    public enum WeildLocation {
        head,
        shoulder,
        hand
    }

    public WeildLocation WeildableLocation { get; set; }

    public Weildable(WeildLocation location, string name, int cost)
        : base(name, cost)
    {
        WeildableLocation = location;
    }

}

public class Weapon : Weildable
{
    public Weapon(string name, int cost) : base(WeildLocation.hand, name, cost) { }
}

public class Helmut : Weildable
{
    public Helmut(string name, int cost) : base(WeildLocation.head, name, cost) { }
}