private void OnTriggerEnter2D(Collider2D collision) { /*If we collide with an item then we want to add it to the Inventory*/ if (collision.gameObject.tag == "Item") { string ItemName = collision.gameObject.name; ItemBase Item = new ItemBase(); ItemManager.items.TryGetValue(ItemName, out Item); Sprite ItemSprite = collision.GetComponent <SpriteRenderer>().sprite; if (cInventory.HasItem(Item.GetName()) && Item.GetStackable() == true) { Item.AddAmount(1); cInventory.UpdateUI(); } else { //Item.SetAmount(1); //Item.SetSpriteImage(ItemSprite); cInventory.AddItem(Item); cInventory.UpdateUI(); } Debug.Log("COLLISION!"); } // if we collide with a bed then show the sleep menu and pause the game if (collision.gameObject.tag == "Bed") { SleepUI.SetActive(true); PauseMenuScript.GameIsPaused = true; //cClock.NightUpdate(); //Debug.Log("COLLISION!"); } // if we collide with the sell chest then enable it if (collision.gameObject.tag == "SellChest") { cChest.DisabledNEnable(); if (!cInventory.ImageParent.gameObject.activeInHierarchy) { cInventory.DisabledNEnable(); } } // if we collide with the shop then enable the shop if (collision.gameObject.tag == "SeedShop") { SeedShopUI.SetActive(true); } if (collision.gameObject.tag == "ToolShop") { ToolShopUI.SetActive(true); } }
// Update is called once per frame void Update() { // View hotbar for cooldown notes if (CoolDown > 0.0f) { CoolDown -= Time.deltaTime; } if (actionLocked) { actionLockedTimer -= Time.deltaTime; if (actionLockedTimer < 0) { actionLocked = false; actionLockedTimer = actionLock; } } // if we aren't actionlocked or paused then we can move if (!actionLocked && !PauseMenuScript.GameIsPaused && !LoadManager.Loading) { /* Move either up, down, left or right, this allow set the bool in the animator */ if (Input.GetKey(KeyCode.W)) { PlayerAnim.SetBool("Up", true); thisObject.transform.position += new Vector3(0, moveSpeed * Time.deltaTime, 0); } else { PlayerAnim.SetBool("Up", false); } if (Input.GetKey(KeyCode.A)) { PlayerAnim.SetBool("Left", true); thisObject.transform.position -= new Vector3(moveSpeed * Time.deltaTime, 0, 0); } else { PlayerAnim.SetBool("Left", false); } if (Input.GetKey(KeyCode.S)) { PlayerAnim.SetBool("Forward", true); thisObject.transform.position -= new Vector3(0, moveSpeed * Time.deltaTime, 0); } else { PlayerAnim.SetBool("Forward", false); } if (Input.GetKey(KeyCode.D)) { PlayerAnim.SetBool("Right", true); thisObject.transform.position += new Vector3(moveSpeed * Time.deltaTime, 0, 0); } else { PlayerAnim.SetBool("Right", false); } /*******************************************************/ // Used to show the inventory to the player. if (Input.GetKey(KeyCode.I)) { if (CoolDown <= 0.0f) { cInventory = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>(); cInventory.DisabledNEnable(); CoolDown = 0.2f; } } } }