Modifying script for equipment

I’m following a tutorial series to create an inventory and equipment system. So far everything has been perfect as far as the UI is concerned, but actually instantiating the objects is giving ne just a little trouble. I’m also not sure which part of the code would need to be changed. As far as I can tell it should work. I’ll try to add as much relevant code as I can.

The first script which controls the equipped items UI

 public void OnPointerDown (PointerEventData)
{
if (inventory.draggingItem)
{
if (index == 2 && inventory.draggedItem.itemType == ItemItemType.MainHand)
{
Item temp = item;
item = item = inventory.draggedItem;
inventory.shiwDraggedItem (temp, -1)

playerEquipment.EquipHand (item = inventory.draggedItem);

The last line of code is referencing the second script which will control things like stats, speed, and any other combat infor I might need. Here is the code for that script:

public void EquipHand (Item item)
{
GameObject itemAsGameObject = (GameObject)Instantiate (Item.itemModel, GameObject.FindObjectWithTag ("Player").transform.position, Quaternion.identity);
itemAsGameObject.GetComponent <DroppedItem>().item = Item;

I’m not sure where the problem is, but the compile log says the issues are with the second script. Specifically the Item.itemModel next to the Instantiate and the very last Item.

Any thoughts?

Capitalization is important! :wink: “Item” is the name of the class, “item” is the name of the variable. It should be:

public void EquipHand (Item item)
{
GameObject itemAsGameObject = (GameObject)Instantiate (item.itemModel, GameObject.FindObjectWithTag ("Player").transform.position, Quaternion.identity);
itemAsGameObject.GetComponent <DroppedItem>().item = item;

Wow, literally all it took to fix it. Thanks a ton!

Hm, I do get a null reference when I spawn the item. Still better than nothing though

Make sure your player actually has the tag “Player” and make sure the item you’re passing in actually has a model in the itemModel field.