- Home /
`Inventory' does not contain a definition for `Add'
Pls Does anyone help me? Assets/Script/Inventory.cs(13,27): error CS0117: Inventory' does not contain a definition for
Add'
Script :
using System.Collections; using UnityEngine; using System.Collections.Generic;
public class Inventory : MonoBehaviour {
public List<Item> inventory = new List<Item>();
private Item_Database database;
// Use this for initialization
void Start () {
database = GameObject.FindGameObjectsWithTag("Item Database");GetComponent<Item_Database>();
inventory.Add(database.items[0]);
Inventory.Add(database.items[1]);
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
for(int i = 0;i < inventory.Count; i++){
GUI.Label(new Rect(10,10,200,50),inventory[i].ItemName);
}
}
}
Sorry i don't understand.. there's a lower case 'i' not an upper case 'i'.
Answer by Klarax · Aug 27, 2014 at 12:15 PM
change
Inventory.Add(database.items[1]);
to
inventory.Add(database.items[1]);
Answer by revolute · Aug 27, 2014 at 12:37 PM
Are you seeing more than one errors? Because I do.
First of all, database = GameObject.FindGameObjectsWithTag("Item Database");GetComponent();
is wrong.
";" is in the way, so change it into "." and use FindWithTag not FindObjectsWithTag as the latter returns a list of items with such tag.
Second, which is your question:
inventory.Add(database.items[0]);
Inventory.Add(database.items[1]); <- uppercase 'I' means you are referencing your own class "Inventory" for a static function not your variable "inventory".
Your answer
Follow this Question
Related Questions
Filling up an array with GameObjects 0 Answers
Script on multiple objects not working properly! 1 Answer
Problems creating new List of type GameObject and adding GameObject to it. 1 Answer
Adds infinite # of components, using GameObject.AddComponent. 4 Answers
How do I add force in the on trigger 1 Answer