protected override void ExecuteUpdate(bool hasFocus, bool pauseMenuOpen) { bool readInput = (hasFocus && !PauseMenu.Instance.IsOpen); Vector2 mouseInput = (readInput ? GetMouseInput() : Vector2.zero); Vector3 dirInput = (readInput ? GetDirInput() : Vector3.zero); if (readInput) { if (Input.GetKeyDown(keybinds.keyInteract)) { if (heldItem == null) { if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit, interactRange)) { WorldItem hitItem = hit.collider.gameObject.GetComponent <WorldItem>(); if (hitItem != null) { hitItem.transform.parent = heldItemParent; hitItem.transform.localPosition = Vector3.zero; hitItem.transform.localScale *= heldItemScale; hitItem.PickUp(); heldItem = hitItem; IsHoldingItem = true; HeldItemType = heldItem.type; } } } else { heldItem.transform.localScale /= heldItemScale; heldItem.transform.parent = null; heldItem.DropToGround(); heldItem = null; IsHoldingItem = false; } } if (Input.GetKeyDown(KeyCode.Mouse0)) { Cursor.lockState = CursorLockMode.Locked; } #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Mouse1)) { hits.Clear(); externalVelocity += cam.transform.forward * 50f; } #endif } if (hasFocus) { Look(mouseInput); } Move(dirInput); }
public bool CheckInteraction() { bool isInteract; Collider2D[] collidersHit = Physics2D.OverlapBoxAll(collider2D.bounds.center, collider2D.size, 0f, layerToCheck); isInteract = collidersHit != null; for (int i = 0; i < collidersHit.Length; i++) { IInteractive interactive = collidersHit[i].GetComponent <IInteractive>(); if (collidersHit[i].CompareTag("Item")) { WorldItem item = collidersHit[i].GetComponent <WorldItem>(); item.PickUp(ref inventory); break; } else if (interactive.ToMonoBehaviour() != null && interactive.CanInteract(null)) { interactive.Interact(null); break; } else if (collidersHit[i].CompareTag("Merchant")) { MerchantWorld merchant = collidersHit[i].GetComponentInParent <MerchantWorld>(); merchant.Interact(); break; } else if (collidersHit[i].CompareTag("EndMapEvent")) { EventEndScene nextLevel = collidersHit[i].GetComponent <EventEndScene>(); nextLevel.Activate(); break; } else if (collidersHit[i].CompareTag("WhaleDialogue")) { dialogue dialogue = collidersHit[i].GetComponent <dialogue>(); dialogue.InitDialog(); break; } } return(isInteract); }