public void AddItem(int x, int y, ItemObj items) { if ((Width - x < items.width) || (length - y < items.height)) { Debug.Log("oc"); PickedUp = false; return; } else { for (int CheckX = x; CheckX < items.width + x; CheckX++) { for (int CheckY = y; CheckY < items.height + y; CheckY++) { if (slots[CheckX, CheckY].Occupied) { Debug.Log("occ"); return; } else { //Debug.Log("yes"); } } } float FloatWidth = items.width; float FloatHeight = items.height; float PositionX; float PositionY; if (OddOrEven(items.width) == 0) { PositionX = (float)(RectTransform.position.x - 440 + 80 * (FloatWidth / 4) + 80 * x); } else { PositionX = (float)(RectTransform.position.x - 440 + 80 * ((FloatWidth - 1) / 2) + 80 * x); } if (OddOrEven(items.height) == 0) { PositionY = (float)(RectTransform.position.y - 280 + 80 * (FloatHeight / 4) + 80 * y); } else { PositionY = (float)(RectTransform.position.y - 280 + 80 * ((FloatHeight - 1) / 2) + 80 * y); } //Debug.Log("divide" + FloatWidth / 2); Instantiate(items.image, new Vector3(PositionX, PositionY, 0), Quaternion.identity, Parent.transform); inventoryData.AddItems(items); PickedUp = true; //Debug.Log(PositionX + " " + PositionY); for (int CheckX = x; CheckX < items.width + x; CheckX++) { for (int CheckY = y; CheckY < items.height + y; CheckY++) { slots[CheckX, CheckY].Occupied = true; //Debug.Log(CheckX + " " + CheckY + " " + slots[CheckX, CheckY].Occupied); } } } }