Raycast over button for certain time activates it

I want to hover the camera raycast icon over a button for a few seconds to activate that button. Any tips?

float buttonTime;
bool inButton;

void Update ()
{
    if (inButton && Time.time > buttonTime)
        //DoStuff
}

void OnMouseEnter ()
{
    buttonTime = Time.time + 3; //Put your desired time here in seconds
    inButton = true;
}

void OnMouseExit ()
{
    inButton = false;
}