private void CheckCommands() { if (Input.GetKeyDown(KeyCode.E)) { RaycastHit hit = new RaycastHit(); Debug.DrawRay(this.collider.bounds.center, this.transform.forward, Color.green, 100.0f); if (Physics.Raycast(this.collider.bounds.center, this.transform.forward, out hit, 100.0f)) { GameObject obj = hit.collider.gameObject; //Get absolute parent while (obj.transform.parent != null) { obj = obj.transform.parent.gameObject; } if (obj.tag == "Chest") { ChestScript chest = (ChestScript)obj.GetComponent(typeof(ChestScript)); //If locked and we have a key if (chest.IsLocked() && keys > 0) { keys--; chest.Open(); } else //Unlocked { chest.Open(); } } } } }
public void Interact() { if (isOpen) { StopInteract(); } else { isOpen = true; UIManager.MyInstance.CloseLeftSide(chestScript); InventoryScript.MyInstance.Open(); CharacterPanel.MyInstance.Open(); spriteRenderer.sprite = openSprite; chestScript.Open(); } }