private void Update() { if (!hasChestBeenFilled) { SetItems(); hasChestBeenFilled = true; } spawnPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); realPoint = new Vector3(spawnPoint.x, spawnPoint.y, 0f); RaycastHit2D hit = Physics2D.Raycast(realPoint, Vector2.zero); float distance = Vector3.Distance(player.position, transform.position); hoveringOver = hit.collider != null ? hit.collider.name : "Nothing"; hoverOverSelf = hit.collider == GetComponent <Collider2D>() && hit.collider != null; if (hoverOverSelf && Input.GetMouseButtonDown(1) && !c.IsAnyChestOpen() && !c.isCraftingMenuActive && distance < 5f) { OpenChest(); c.ToggleCraftingMenu(); isChestOpen = true; } else if (Input.GetKeyDown(KeyCode.C) && c.IsAnyChestOpen()) { CloseChest(); c.ToggleCraftingMenu(); isChestOpen = false; } }
private void Update() { spawnPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); realPoint = new Vector3(spawnPoint.x, spawnPoint.y, 0f); RaycastHit2D hit = Physics2D.Raycast(realPoint, Vector2.zero); #region Showing Trade Interface string pureR = currentItemsSelling[currentIndexShowing]; string pureP; if (traderType == "Forger") { pureP = allForgerTradesPossible[currentItemsSelling[currentIndexShowing]]; p = pureP.Split('x'); } else if (traderType == "Rancher") { pureP = allRancherTradesPossible[currentItemsSelling[currentIndexShowing]]; p = pureP.Split('x'); } else if (traderType == "Lumberjack") { pureP = allLumberJackTradesPossible[currentItemsSelling[currentIndexShowing]]; p = pureP.Split('x'); } r = pureR.Split('x'); reactant = r[0]; product = p[0]; reactantAmount = Int32.Parse(r[1]); productAmount = Int32.Parse(p[1]); reactantAmountText.text = reactantAmount > 1 ? r[1] : ""; productAmountText.text = productAmount > 1 ? p[1] : ""; tradeCounterText.text = string.Format("{0}/{1}", currentIndexShowing + 1, currentItemsSelling.Count); reactantImage.sprite = spriteMatcher[reactant]; productImage.sprite = spriteMatcher[product]; #endregion hoveringOver = hit.collider != null ? hit.collider.name : "Nothing"; hoverOverSelf = hit.collider == GetComponent <Collider2D>() && hit.collider != null; if (hoverOverSelf && Input.GetMouseButtonDown(1) && !c.IsTradingMenuActive() && !c.isCraftingMenuActive) { OpenTradingMenu(); c.ToggleCraftingMenu(); isTradingMenuActive = true; } else if (Input.GetKeyDown(KeyCode.C) && c.IsTradingMenuActive()) { CloseTradingMenu(); c.ToggleCraftingMenu(); isTradingMenuActive = false; } }