Exemplo n.º 1
0
        public override void React(MonoBehaviour behaviour, Interactable interactable)
        {
            _inventory.AddItem(Item);

            if (interactable == null)
            {
                return;
            }
            Destroy(interactable.transform.gameObject);
        }
Exemplo n.º 2
0
    private void GetPlayerInputs()
    {
        horizontal      = Input.GetAxis("Horizontal");
        vertical        = Input.GetAxis("Vertical");
        mouseHorizontal = Input.GetAxis("Mouse X");
        mouseVertical   = Input.GetAxis("Mouse Y");
        if (Input.GetButtonDown("Sprint"))
        {
            isSprinting = true;
        }
        if (Input.GetButtonUp("Sprint"))
        {
            isSprinting = false;
        }
        if (isGrounded && Input.GetButton("Jump"))
        {
            jumpRequest = true;
        }

        float scroll = Input.GetAxis("Mouse ScrollWheel");

        if (scroll != 0)
        {
            if (scroll > 0)
            {
                selectedBlockIndex++;
            }
            else
            {
                selectedBlockIndex--;
            }
            //Allows for scrolling back around to the beginning
            if (selectedBlockIndex > (byte)(BlockTypes.ALL_BLOCKS.Length - 1))
            {
                selectedBlockIndex = 1;
            }
            if (selectedBlockIndex < 1)
            {
                selectedBlockIndex = (byte)(BlockTypes.ALL_BLOCKS.Length - 1);
            }
            updatePlaceBlockType();
        }

        if (hightlightBlock.gameObject.activeSelf)
        {
            //Destroy Block
            if (Input.GetMouseButtonDown(0))
            {
                Chunk c         = world.GetChunk(hightlightBlock.position);
                Item  blockItem = new Item(c.GetBlockType(hightlightBlock.position).GetItemType(), 1);
                if (blockItem.GetItemType() != ItemTypes.NO_ITEM)
                {
                    playerInventory.AddItem(blockItem);
                }
                c.EditVoxel(hightlightBlock.position, BlockTypes.AIR);
            }
            //Place Block
            else if (Input.GetMouseButtonDown(1))
            {
                world.GetChunk(placeBlock.position).EditVoxel(placeBlock.position, BlockTypes.ALL_BLOCKS[selectedBlockIndex]);
            }
        }

        if (highlightedEntity != null)
        {
            if (Input.GetButtonDown("EntityInteract"))
            {
                highlightedEntity.Interact(this);
            }
        }
    }