So basically I’m working on implementing a inventory and I got the item to destroy and add to my inventory but when if click the item on the inventory it is supposed to (for now) just instantiate back at the players position but I’m getting a MissingReference.
I read a few places to get a instance of the instantiation but I’m not sure where to go from there.
Any ideas?
This controls the inventory buttons and the instantiation
void OnGUI () {
if (disp) {
float yOffset = 5;
GUI.Box (new Rect(xOffset, 0, winWidth, winHeight), "");
for (int i = 0; i < invent.Count; i++) {
if (GUI.Button (new Rect(buttonXOffset, yOffset, buttonWidth, buttonHeight), invent[i].itemName)) {
Instantiate (invent[i].itemPrefab, player.position, Quaternion.identity);
}
GUI.Box (new Rect(amtXOffset, yOffset, amtWidth, buttonHeight), invent[i].itemQuantity.ToString ());
yOffset += 5 + buttonHeight;
}
}
}
this is my BaseItem
using UnityEngine;
using System.Collections;
public class BaseItem : MonoBehaviour {
private InventoryMaster inv;
private bool lootable = false;
public bool canLoot = true;
public GameObject itemPrefab;
public string itemName;
public string itemDescription;
public Texture itemIcon;
public SlotType itemSlot;
public int itemQuantity;
public int itemValue;
public int itemMass;
public int itemId;
public int maxStack = 60;
private Transform player;
private float dist;
private Transform myTransform;
// Use this for initialization
void Start () {
myTransform = transform;
player = GameObject.FindGameObjectWithTag ("Player").transform;
inv = GameObject.Find ("GameMaster").GetComponent<InventoryMaster>();
}
// Update is called once per frame
void Update () {
if (canLoot) {
dist = Vector3.Distance (player.position, myTransform.position);
if (Input.GetButtonDown ("Interact")) {
//if (dist < 4.0f) {
Loot ();
//}
}
}
}
public void Loot() {
if (lootable) {
inv.AddItem (this);
Destroy (myTransform.gameObject);
}
}
void OnMouseEnter() {
lootable = true;
}
void OnMouseExit() {
lootable = false;
}
public enum SlotType {
//Armor
Head,
Chest,
Legs,
Feet,
Gloves,
//Weapons
Weapon,
Ammo,
//Items
Item
}
}
this is all I have right now for getting the instantiation
private void Die() {
Destroy (this.gameObject);
lootClone = Instantiate (posLoot[0], transform.position, Quaternion.identity) as GameObject;
}
Any ideas on how to make this work?