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 NKRdev · Nov 25, 2013 at 02:21 PM · c#errorfpsinventorymmo

Perfect inventory code giving errors? [C#]

I can't understand why this code is giving me so many errors, it seems perfectly fine to me but yet i'm getting errors on lines :

  • 26

  • 30

  • 32

  • 33

  • 53

  • 54

  • 62

Can someone please help me figure out the problem?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class InventorySys : MonoBehaviour
 {
 // Remade the code and took out most of the comments sense everything is self-explanitory -- to keep it sexy..
     public List<Items> Inventory;
     public Items[] playerInventory;
     public Rect inventoryWindow = new Rect (0,0,600,600);
     private RaycastHit drug;
     private Ray lord;
     
     void Awake ()
     {
         Inventory = new List<Items> (); // Needed to be initialized.
     }
 
     void Update ()
     {
         
         Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         
         if (Input.GetButtonDown("Fire1")) { // If object on ground is clicked on -->
             
             if (Physics.Raycast(Ray,out drug, 20)) {
                 
                 for (int x = 0; x < playerInventory.Length; x++) { // Check the player's entire inventory to see if it already has the item -->
                     
                     if (drug.collider.tag == playerInventory[i].itemID.ToString()) { 
                         
                         Inventory.Add(playerInventory[i]); // Adding to our inventory.
                         Destroy(drug.collider.gameObject); // Once the player picks up the object, we destroy the object from the floor.
                     }
                 } 
             }
         }
     }
     
     
     
     
     // Really simple GUI code for testing purposes. 
     
     void insideInventory (int windowID) {
         
         int expandRec = 20;
         GUI.DragWindow(new Rect(0,0,600,20));
         
         for (int i = 0; i < Inventory.Count; i++){// Finding everything in solid inventory. The player inventory is for grabbing objects and fowarding them into the solid inventory.
         
             GUI.Button(new Rect(20, expandRec, 64, 65), Inventory[i].icon); // Creates small buttons with our icons on them.
             GUI.Label(new Rect(70, expandRec, 64, 65), Inventory[i].name);
             GUI.Label(new Rect(90, expandRec, 64, 200), Inventory[i].description);
           GUI.Button(new Rect(100, expandRec, 64, 65), "Power Level : " + Inventory[i].itemPowerLevel.ToString() + "Damage!");
     
             // You get the point.
     }
      }    
     
     void OnGUI() {
         InventoryWindow = GUI.Window(0, inventoryWindow, insideInventory, "Inventory Menu by XX!");
     }
     
 }
  


which is from a class like this :

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [System.Serializable]
 public class Items {
 
 public string itemName; 
 public string itemDescription; 
 public int itemPowerLevel;
 public int itemDamage; 
 public int itemRange; // Don't know if this was needed, but whatever. EX : Kirito's Bow - Range : 500-600.
 public int itemID;
 public int itemPrice; 
 public GameObject attachObject;
 public Texture2D icon; // Attaching an icon.
 public Transform itemPrefab; // Prefab for item.
 
 public enum ItemGroup{ Weapon, Clothing, Potion, Quest, Recipe, MescItem } // Can't think of anything else.
 public ItemGroup itemCategory;
 
     // Constructors.
 
 /**
 public Items_X InvetoryCon = new Items_X(0, 0, 0, 0, 0); // Instance.
 
    public Items_X(int d, int r, int u, int g, int s) 
         {
             itemPowerLevel= d;
             itemRange = r;
             
             // ^ add on, if needed.
         }
         
         **/
 
     
 }
 
Comment
Add comment · Show 2
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 ABerlemont · Nov 25, 2013 at 02:28 PM 0
Share

It will help to copy/paste the errors as well.

avatar image ABerlemont · Nov 25, 2013 at 02:31 PM 0
Share

26 >> Ray is a class, not a variable | 32 >> don't you have already class named Inventory ? I would suggest not using a capital first letter to variable.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Bunny83 · Nov 25, 2013 at 02:35 PM

"Perfect inventory code"... That's a joke, right? :D

  • The code has very inconsistent nameing. Some variables starts with a capital letter (which should start with a lower case letter) and some Methods start with a lowercase letter (which should be upper case).

  • in line 22 you try to assign a Ray to the Ray class which doesn't make any sense. You might wanted to assign it to "lord".

  • Just a followup: lord? drug? d, r, u, g, s? Worst possible names here. Variable names should tell you something about the use of a variable.

  • In line 26 you again pass the class Ray where you should pass an instance of the class Ray. (lord? can you hear me?).

  • A class that represents an item should be named "Item", not "Items".

  • Your "Items" class doesn't have a "name" or a "description". You called them itemName and itemDescription, which is btw redundant. You should rename the variables and remove the "item" from the names.

Comment
Add comment · 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

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

error CS1061 anybody might help me? 1 Answer

I am having a problem with the following script 1 Answer

Scrolling inventory script giving argument out of range. 2 Answers

c# Weapon Pickup Script 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