Raycast is not working

I’m trying to write a simple script for my game. When the player presses E while looking at an object, I want something to happen. However, the raycast only seems to work when I look at a very specific part of my object (I’m using a cube at the moment). Any reasons why?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickupitem : MonoBehaviour
{
    void Update()
    {
        RaycastHit hit;
        if (Input.GetKey(KeyCode.E))
        {
            if (Physics.Raycast(transform.position, transform.forward, out hit) && hit.transform.tag == "Button")
            {
                Debug.Log("test");
            }
        }
    }
}

check the collider of your cube, make sure it is the size you want it.