//connect our player to the player variable via tag //connect our Camera to the mainCam variable via tag #endregion #region Update private void Update() { //if our interact key is pressed if (Input.GetKeyDown(KeyCode.E)) { //create a ray Ray interact; //this ray is shooting out from the main cameras screen point center of screen interact = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)); //create hit info RaycastHit hitInfo; //if this physics raycast hits something within 10 units if (Physics.Raycast(interact, out hitInfo, 10)) { #region NPC tag //and that hits info is tagged NPC if (hitInfo.collider.CompareTag("NPC")) { // HCDialogue dlg = hitInfo.transform.GetComponent<HCDialogue>(); NPCDialogue dlg = hitInfo.transform.GetComponent <NPCDialogue>(); if (dlg != null) { dlg.OpenDLGWindow(); Movement.canMove = false; Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } //Debug that we hit a NPC Debug.Log("NPC"); } #endregion #region Item //and that hits info is tagged Item if (hitInfo.collider.CompareTag("Item")) { //Debug that we hit an Item Debug.Log("Item"); ItemHandler handler = hitInfo.transform.GetComponent <ItemHandler>(); if (handler != null) { handler.OnCollection(); } } #endregion #region Gate tag //and that hits info is tagged NPC if (hitInfo.collider.CompareTag("Gate")) { //Debug that we hit a NPC Debug.Log("Gate"); } #endregion } } }