// Update is called once per frame void Update() { currentItemHolder = GameObject.Find("CurrentItemSelector").GetComponent <CurrentItem>().currentSlot; if (currentItemHolder.transform.childCount > 0) { currentItem = currentItemHolder.GetComponentInChildren <LittleHeightsItem>(); } else { currentItem = null; } if (Input.GetKeyDown(KeyCode.P)) { SaveInventory(); } }
// Start is called before the first frame update void Start() { hotbarSlot1 = GameObject.Find("hotbarItem (1)").GetComponent <HotbarItemHolder>(); hotbarSlot2 = GameObject.Find("hotbarItem (2)").GetComponent <HotbarItemHolder>(); hotbarSlot3 = GameObject.Find("hotbarItem (3)").GetComponent <HotbarItemHolder>(); hotbarSlot4 = GameObject.Find("hotbarItem (4)").GetComponent <HotbarItemHolder>(); hotbarSlot5 = GameObject.Find("hotbarItem (5)").GetComponent <HotbarItemHolder>(); hotbarSlot6 = GameObject.Find("hotbarItem (6)").GetComponent <HotbarItemHolder>(); currentSlotNum = 1; currentSlot = hotbarSlot1; gameSlotIdentifier = this.GetComponent <Image>(); hotBarSlotNum = new Dictionary <int, HotbarItemHolder>() { { 1, hotbarSlot1 }, { 2, hotbarSlot2 }, { 3, hotbarSlot3 }, { 4, hotbarSlot4 }, { 5, hotbarSlot5 }, { 6, hotbarSlot6 } }; }
// Update is called once per frame void Update() { isActive = activeTileSelector.GetComponent <MouseHoverScript>().isActiveArea; currentItem = playerInventory.currentItem; mousePosition = placeableItemTileMap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (currentItem && isActive && ItemProperties.itemIsPlaceable[currentItem.id]) { tryToHoverTile(currentItem.id); if (Input.GetMouseButtonDown(1)) { Debug.Log("tried to place " + currentItem.id); // Debug.Log("tried to place on " + ItemProperties.itemsTilemap[currentItem.id]); Debug.Log("tried to make prefab " + ItemProperties.itemPlaced[currentItem.id]); try { if (!checkIfItemThere()) { placedItem = Instantiate(Resources.Load("PlaceableItem/" + currentItem.id), grid.GetCellCenterWorld(mousePosition), Quaternion.identity) as GameObject; HotbarItemHolder hotbarItemHolder = hotBarItem.currentSlot; Debug.Log("Position: " + grid.GetCellCenterWorld(mousePosition)); hotbarItemHolder.itemHolderOnInventory.GetComponentInChildren <LittleHeightsItem>().subtractQuantity(1); } else { Debug.Log("Item already there"); } } catch { Debug.Log("error placing item"); } } } else { placeableItemTileMap.SetTile(prevPos, null); placeableItemTileMap.SetTile(currPos, null); } }
// Update is called once per frame void Update() { currentSlot = hotBarSlotNum[currentSlotNum]; this.transform.position = new Vector3(currentSlot.transform.position.x, currentSlot.transform.position.y, currentSlot.transform.position.z); if (Input.GetAxis("Mouse ScrollWheel") > 0f) { scrollDown(); } else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { scrollUp(); } if (Input.GetKeyDown(KeyCode.Alpha1)) { currentSlotNum = 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { currentSlotNum = 2; } if (Input.GetKeyDown(KeyCode.Alpha3)) { currentSlotNum = 3; } if (Input.GetKeyDown(KeyCode.Alpha4)) { currentSlotNum = 4; } if (Input.GetKeyDown(KeyCode.Alpha5)) { currentSlotNum = 5; } if (Input.GetKeyDown(KeyCode.Alpha6)) { currentSlotNum = 6; } }
//GameObject hotbar; void awake() { currentItemHolder = GameObject.Find("CurrentItemSelector").GetComponent <CurrentItem>().currentSlot; }