Example #1
0
    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);
    }