Good day,
I am trying to build a game that uses an inventory. The game works so that when player character clicks an object it disapperas from the map and adds the item to inventory.
However, I can’t make Unity register the mouse clicks on the collider of items. The clicks in game have thus far given errors and with the current script the game doesn’t even start. Help is now very welcome.
static public Dictionary<int, string> KeyDictionary = new Dictionary<int, string>
{
{0, "Golden Key"},
{1, "string.Empty"},
};
ItemClass1 ItemObject = new ItemClass1 ();
Inventory1 Inventory = new Inventory1 ();
public Ray mouseRay;
public RaycastHit rayHit;
void Start () {
KeyDictionary [0] = ItemObject.KeyItems.name;
}
void Update () {
//mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
//Press the mouse putton
if (Input.GetMouseButtonDown (0))
{
//If the mouse touches the collider
if (Physics.Raycast (Camera.ScreenPointToRay (Input.mousePosition), out rayHit))
{
//Add item to inventory and destroy the object from the map
if (KeyDictionary [0] != string.Empty) {
Inventory1.inventoryNameDictionary [0] = KeyDictionary [0];
KeyDictionary [0] = string.Empty;
Destroy (gameObject);
Inventory.isKey = true;
}
}
}
if (Input.GetKeyDown (KeyCode.A)) {
//inventoryWindowToggle = false;
}
/*Physics.Raycast (mouseRay, out rayHit);
if (rayHit.collider.transform.tag == "Key")
{
inventoryWindowToggle = true;
}*/
}
}