Looking for show/ hide script

Does anyone know of a script that can be attached to a gameobject with a mesh renderer. When the object is x amount of units away from the main camera the object turns off the mesh renderer, when the object is close again, the mesh renderer is turn back on. I am just looking for some optimization for a big level where I dont need to see far away objects. I thought Unity would have this built into it but apparently not.
Thanks for any help

There sure is but even better than going around adding a script to every object you want to make visible.

function Start () {
    var distances = new float[32];
    // Set up layer 10 to cull at 15 meters distance.
    // All other layers use the far clip plane distance.
    distances[10] = 15;
    camera.layerCullDistances = distances;
}

Awesome thanks!