void Update() { storedLocations.Push(this.gameObject.transform.position); //save the positions of the player. Used in Obstruction Class to set correct collision point. if (rightClickMenu == true) { if (agent.enabled) { agent.SetDestination(itemClickedDestination); } else { agent.enabled = true; agent.SetDestination(itemClickedDestination); } rightClickMenu = false; } //Debug.Log("itemclicked: " + itemClicked); if (obstruction != null && touching && !interactedOnce && (obstructionPosition == obstruction.transform.position)) { Debug.Log("Touching desired obstruction, will now attempt to interact with it"); obstruction.CheckItemUsed(usedOnObstructionReference); interactedOnce = true; } /** * Pick up the item if it was the last thing that was clicked. * */ if (itemClicked && agent.transform.position == itemClickedDestination || itemClicked && NextToItemUnderObstruction())// || agent.transform.position == rightClickMoveTo.point) { //get correct index int index = itemClicked.sceneItemIndex; //Debug.Log("index is: "+ index); //Remove the item from the list and the position for (int idx = 0; idx < trackItemsScript.itemsOnGround.Count; idx++) { if (trackItemsScript.itemsOnGround[idx].GetComponent <Item>() == itemClicked && trackItemsScript.itemPositions[idx] == itemClicked.transform.position) { if (itemClicked.spawn) { //Debug.Log("Item can respawn: " + trackItemsScript.sceneItems[index].gameObject.GetComponent<Item>()); StartCoroutine(spawnScriptReference.SpawnItem(trackItemsScript.sceneItems[index].gameObject.GetComponent <Item>(), trackItemsScript.sceneItems[index].gameObject.GetComponent <Item>().spawnTime)); int nonRespawnIndex = trackItemsScript.sceneItems[index].gameObject.GetComponent <Item>().allGameItemsReferenceIndex; //Debug.Log(nonRespawnIndex+" "+ trackItemsScript.allGameItemsReferenceList[nonRespawnIndex]); inventory.ClickToPickUpItem(trackItemsScript.allGameItemsReferenceList[nonRespawnIndex].gameObject.GetComponent <Item>(), index); } else { //this next line here is very important, otherwise we keep adding more spawns into the game when dropping regular items. index = itemClicked.allGameItemsReferenceIndex; //Debug.Log("Item can't respawn: " + index); inventory.ClickToPickUpItem(trackItemsScript.allGameItemsReferenceList[index].gameObject.GetComponent <Item>(), index); } GameObject item = trackItemsScript.itemsOnGround[idx]; //Debug.Log("ClickToMove remove items from the list index:" + item.GetComponent<Item>().sceneItemIndex); trackItemsScript.itemPositions.RemoveAt(idx); trackItemsScript.itemsOnGround.RemoveAt(idx); Destroy(item); } } } /** * This code is executed whenever we're not hovered over the inventory. * */ if (!EventSystem.current.IsPointerOverGameObject()) { //Raycast used to check for items on the ground and to register player movement. RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, itemsGroundObstructions)) { //Ray intersecting with collider (Only find colliders in the mask passed through) CheckItemHover(hit); CheckGroundClick(hit); } else { HideItemMouseOverName(); } } else if (Input.GetMouseButtonDown(0)) { StartCoroutine(DisplayMouseClick(clickInventoryCursor)); } }