I’d like to use list to made inventory.
Here my first script holding all my items…
public class Items {
var Name : String;
var Type : String;
var Gameobjname: String;
var Description : String;
var Qty : int;
var Weight : float;
public function Items(nam : String, typ : String, gam : String, des : String, qt : int, wg : float){
Name = nam;
Type = typ;
Gameobjname = gam;
Description = des;
Qty = qt;
Weight = wg;
}
}
public class Createditems {
//ressources
public var WaterItem : Items = new Items("Water", "Ressource", "None", "Unit of Water", 1, 0);
public var RockItem : Items = new Items("Rock", "Ressource", "None", "Unit of rock", 1, 0);
public var RawmetalItem : Items = new Items("Raw Metal", "Ressource", "None", "Unit of Raw Metal", 1, 0);
public var SandItem : Items = new Items("Sand", "Ressource", "None", "Unit of Sand", 1, 0);
//armes
public var RocketlaunchItem : Items = new Items("Rocket Launcher", "Turret", "None", "Rocket Launcher", 1, 0);
public var AntirocketlaunchItem : Items = new Items("Anti Rocket Launcher", "Turret", "None", "Anti Rocket Launcher", 1, 0);
//munitions
public var RocketItem : Items = new Items("Rocket", "Ammo", "None", "Unit of Rocket", 1, 0);
public var AntirocketItem : Items = new Items("Anti Rocket", "Ammo", "None", "Unit of Anti Rocket", 1, 0);
}
But I can>t add those “items” to my inventory list…
import System.Collections.Generic;
var items : Createditems = new Createditems ();
var InvList : List.<Items> = new List.<Items>();
function Start () {
Debug.Log(items.WaterItem.Name); //Working
InvList.add(items.WaterItem); //Not working
}
I tried to fix this on many way but nothing work. Always show this kind of error: MissingMethodException: Method not found…