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*.itemID.ToString()) {* 

_ Inventory.Add(playerInventory*); // 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*.icon); // Creates small buttons with our icons on them.
GUI.Label(new Rect(70, expandRec, 64, 65), Inventory.name);
GUI.Label(new Rect(90, expandRec, 64, 200), Inventory.description);
GUI.Button(new Rect(100, expandRec, 64, 65), "Power Level : " + Inventory.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.*
}

_ **/_

}

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

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 Answer

1

“Perfect inventory code”… That’s a joke, right? :smiley:

  • 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.