public void ArrangeOk() { int putable = 0; for (int i = 0; i < farmAnimal.transform.childCount; i++) { if (Mathf.Abs(farmAnimal.transform.GetChild(i).transform.position.x - arrangeImage.transform.position.x) > 3 || Mathf.Abs(farmAnimal.transform.GetChild(i).transform.position.y - arrangeImage.transform.position.y) > 3) { putable++; } } for (int i = 0; i < farmObjects.transform.childCount; i++) { if (Mathf.Abs(farmObjects.transform.GetChild(i).transform.position.x - arrangeImage.transform.position.x) > 3 || Mathf.Abs(farmObjects.transform.GetChild(i).transform.position.y - arrangeImage.transform.position.y) > 3) { putable++; } } if (putable == farmAnimal.transform.childCount + farmObjects.transform.childCount) { inventory.SetActive(true); putButton.SetActive(false); cancelButton.SetActive(false); Spawner._instance.farmObjects[InputManager.farmObjectIndex].harvestTime = System.DateTime.Now; GameObject arranged = Instantiate(invenItems[InputManager.farmObjectNumber], new Vector2(arrangeImage.transform.position.x, arrangeImage.transform.position.y), Quaternion.identity); FarmObjectController farmObjectController = arranged.GetComponent <FarmObjectController>(); FarmObject farmObject = arranged.GetComponent <FarmObject>(); farmObject.harvestTime = System.DateTime.Now; farmObjectController.state = FarmObjectController.State.producing; SpriteRenderer spriteRenderer = farmObjectController.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = farmObjectController.producingSprite; arranged.transform.parent = farmObjects.transform; Spawner._instance.farmObjects[InputManager.farmObjectIndex].posX = arrangeImage.transform.position.x; Spawner._instance.farmObjects[InputManager.farmObjectIndex].posY = arrangeImage.transform.position.y; Spawner._instance.farmObjects[InputManager.farmObjectIndex].isField = true; Drag arrangeImageDrag = arrangeImage.GetComponent <Drag>(); arrangeImageDrag.PItransformBack(); DataManager._instance.ParseFarmObjectData(Spawner._instance.farmObjects); inventorySlotNum--; for (int i = InputManager.inventorySlotNumber; i <= inventorySlotNum; i++) { Image invenSlotImage = inventoryContents.transform.GetChild(i).gameObject.GetComponent <Image>(); Image nextInvenSlotImage = inventoryContents.transform.GetChild(i + 1).gameObject.GetComponent <Image>(); invenSlotImage.sprite = nextInvenSlotImage.sprite; FarmObject invenSlotFarmOb = inventoryContents.transform.GetChild(i).gameObject.GetComponent <FarmObject>(); FarmObject nextInvenSlotFarmOb = inventoryContents.transform.GetChild(i + 1).gameObject.GetComponent <FarmObject>(); invenSlotFarmOb.farmObjectIndex = nextInvenSlotFarmOb.farmObjectIndex; invenSlotFarmOb.farmObjectNumber = nextInvenSlotFarmOb.farmObjectNumber; } for (int i = 0; i < farmAnimal.transform.childCount; i++) { AnimalController animalController = farmAnimal.transform.GetChild(i).GetComponent <AnimalController>(); animalController.pathStart(); } } }
void Update() { if (Input.GetMouseButtonDown(0) && !inventory.activeSelf) { mousePosition = Input.mousePosition; mousePosition = Camera.ScreenToWorldPoint(mousePosition); RaycastHit2D hit = Physics2D.Raycast(mousePosition, transform.forward, maxDistance); Debug.Log(hit.collider.gameObject.name); if (hit.collider == null) { } else if (hit.collider.gameObject != tapzone) { if (hit.collider.gameObject.transform.parent.name == farmObjects.name && arrangeImage.transform.position.x < -23) { FarmObjectController farmObjectController = hit.collider.gameObject.GetComponent <FarmObjectController>(); if (farmObjectController.state == FarmObjectController.State.producing && map.activeSelf == false) { tapObject = hit.collider.gameObject; putInvenButton.SetActive(true); offPutInvenButton.SetActive(true); farmObjectNumber = hit.collider.gameObject.GetComponent <FarmObject>().farmObjectNumber; farmObjectIndex = hit.collider.gameObject.GetComponent <FarmObject>().farmObjectIndex; } farmObjectController.Harvest(); } } else if (hit.collider.gameObject.name != putInvenButton.name) { MoneyManager.MoneyUP(oneTapMoney); if (arrangeImage.transform.position.x > -22 && arrangeImage.transform.position.x < 22 && arrangeImage.transform.position.y > -7 && arrangeImage.transform.position.y < 10 && mousePosition.x > -22 && mousePosition.x < 22 && mousePosition.y > -7 && mousePosition.y < 10) { Debug.Log("왜죠"); Drag drag = arrangeImage.GetComponent <Drag>(); drag.ChangePos(mousePosition.x, mousePosition.y); } } } }