private void OnTriggerStay2D(Collider2D collider) { Pack pack = GetComponentInParent <Pack>(); DroppedItem di; if (collider.gameObject.TryGetComponent(out di) && di.canPickUp) { if (Vector3.Distance(collider.transform.position, transform.position) <= collectRange) { int remain = pack.AddItem(di.Item); if (remain > 0) { Item item = di.Item; item.count -= remain; di.Item = item; } else { Destroy(di.gameObject); } } else { collider.transform.position += Vector3.Normalize(transform.position - collider.transform.position) * Time.deltaTime * collectSpeed; } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { Item pickaxe = ItemObjectFactory.Instance.GetItemObject(4).CreateItem(1); pack.AddItem(pickaxe); } if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { UseItem(true); } } if (Input.GetMouseButtonUp(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { UseItem(false); } } if (Input.GetKeyDown(KeyCode.R)) { CostMap costs = Navigation.CreateCostMapFromBlockMap(new Vector3Int(0, 0, 0), new Vector3Int(31, 31, 0), 1); Vector3Int[] path = Navigation.FindPath(new Vector3Int(0, 0, 0), new Vector3Int(31, 31, 0), costs); for (int i = 0; i < path.Length; i++) { GameObject go = BlockMap.Instance.GetBlockGameObject(path[i]); SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); sr.color = Color.blue; } } if (Input.GetKeyDown(KeyCode.E)) { if (PackUIController.Instance.Expanded) { PackUIController.Instance.Collapse(); RecipeListUIController.Instance.gameObject.SetActive(false); } else { PackUIController.Instance.Expand(); RecipeListUIController.Instance.gameObject.SetActive(true); RecipeListUIController.Instance.UpdateUI(RecipeFactory.Instance.getRecipes()); } } SelectPackSlot(); }