How do I restore a shader after a raycast?

Hi. If I change the transparency of a shader once it is hit by a raycast using the code below, how can I restore it after it is no longer being "hit" by the raycast?

void Update() {

    RaycastHit hit;

    if (Physics.Raycast(transform.position, transform.forward, 10))
    {
        //changes the shader and transparency
        hit.collider.renderer.material.shader = Shader.Find("Transparent/Diffuse");
        Color color = hit.collider.renderer.material.color;
        color.a = 0.5f;
        hit.collider.renderer.material.color = color;

    }

Save the hit collider in a local var, and add an 'else' clause which restores it. You may want a 'sentinal' boolean or something (or just use said var) to test that it was 'just hit' or 'just un-hit' so you don't have to reset it on every frame.