- Home /
My inventory scripts
I started following this tutorial on youtube and I got to a point where their is just one error from stopping me. Then I researched it a lot of people had this problem but so I found a completed version of the script that was released online I tested it out and I still get the single error.
//my error Assets/my menu/FOLLOW ME/MYGUI/MyGui.cs(13,22): error CS0246: The type or namespace name `Item' could not be found. Are you missing a using directive or an assembly reference?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class myGUI : MonoBehaviour {
public float lootWindowHeight = 90;
public float buttonWidth = 40;
public float buttonHeight = 40;
public float closeButtonWidth = 20;
public float closeButtonHight = 20;
private List<Item> _lootItems;
private bool _displayLootWidnows = false;
private float _offset = 10;
private const int LOOT_WINDOWS_ID = 0;
private Rect _lootWindowsRect = new Rect(0,0,0,0);
private Vector2 _lootWindowSlider = Vector2.zero;
private GameObject chest;
// Use this for initialization
void Start () {
_lootItems = new List<Item>();
}
public void OnEnable() {
Messenger<int, GameObject>.AddListener("PopulateChest", PopulateChest);
}
public void OnDisable() {
Messenger<int, GameObject>.RemoveListener("PopulateChest", PopulateChest);
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
if(_displayLootWidnows)
_lootWindowsRect = GUI.Window(LOOT_WINDOWS_ID, new Rect(_offset, Screen.height - (_offset + lootWindowHeight), Screen.width - (_offset * 2), lootWindowHeight), LootWindow, "Loot Window");
}
private void LootWindow(int id) {
if(GUI.Button(new Rect(_lootWindowsRect.width - 20, 0, closeButtonWidth, closeButtonHight), "x")) {
ClearWindow();
}
_lootWindowSlider = GUI.BeginScrollView(new Rect(_offset * .5f, 15, _lootWindowsRect.width - 10, 70), _lootWindowSlider, new Rect(0, 0, (_lootItems.Count * buttonWidth) + _offset, buttonHeight * _offset));
for(int cnt = 0; cnt < _lootItems.Count; cnt++) {
GUI.Button(new Rect(5 + (buttonWidth * cnt), 8, buttonWidth, buttonHeight), cnt.ToString());
}
GUI.EndScrollView();
}
private void PopulateChest(int x, GameObject go) {
chest = go;
for(int cnt = 0; cnt < x; cnt++) {
_lootItems.Add(new Item());
_displayLootWidnows = true;
}
}
private void ClearWindow() {
_lootItems.Clear();
chest.GetComponent<Chest>().OnMouseUp();
chest = null;
_displayLootWidnows = false;
}
}
Answer by iwaldrop · Feb 06, 2013 at 03:51 AM
The error is telling you that you don't have a class called Item anywhere. Your inventory is, essentially, made up of a list of Items, but you haven't defined what an Item is! (Or at least it hasn't been defined in this script). :) Check and see if there was anything more to the tutorial; you need to have an Item class for this script to work.
Also keep in $$anonymous$$d that there is nothing stopping you from implementing your own Item class. Either way, it would be a good idea to make the Item a generic class that you can extend later on to have different kinds of items.
he said much the same thing to someone else in his comments. I'll get on that tomorrow.
Your answer
Follow this Question
Related Questions
How to create a List containing all the different variables within a script (regardless of type)? 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to make a Keypad for a locked door 2 Answers
Trying to Highlight text in order to copy and paste, but do not want the text to be editable. 1 Answer