Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ryno9788 · Feb 06, 2013 at 03:46 AM · c#guilistsgenericsmenu-item

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;           
         }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iwaldrop · Feb 06, 2013 at 03:53 AM 0
Share

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.

avatar image ryno9788 · Feb 06, 2013 at 04:07 AM 0
Share

he said much the same thing to someone else in his comments. I'll get on that tomorrow.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges