Activate camera effect when inside a volume (with script)

I’ve taken this simple but interesting script around on the forum or Wiki (don’t remember).

//This script enables underwater effects. Attach to main camera.

//Define variables
var underwaterLevel = 7;

//The scene's default fog settings
private var defaultFog = RenderSettings.fog;
private var defaultFogColor = RenderSettings.fogColor;
private var defaultFogDensity = RenderSettings.fogDensity;
private var defaultSkybox = RenderSettings.skybox;
var noSkybox : Material;

function Start () {
    //Set the background color
    camera.backgroundColor = Color (0, 0.4, 0.7, 1);
}

function Update () {
    if (transform.position.y < underwaterLevel) {
        RenderSettings.fog = true;
        RenderSettings.fogColor = Color (0, 0.4, 0.7, 0.6);
        RenderSettings.fogDensity = 0.04;
        RenderSettings.skybox = noSkybox;
    }
    
    else {
        RenderSettings.fog = defaultFog;
        RenderSettings.fogColor = defaultFogColor;
        RenderSettings.fogDensity = defaultFogDensity;
        RenderSettings.skybox = defaultSkybox;
    }
}

But I would like to add it to an area (box) so that when the camera enters that area it activates the features.
How to do this?

I guess I must take off the var underwater level and replace it with the parent object referral, first of all.
Then at the IF statement I’ll have to check if the camera position is inside the box. Is there a single command to do this?

Thank you.

Instead of relying on the y position, use a trigger.

This would of course require that the colliding object has a rigidbody attached. It can be set to kinematic if you are moving the object about by script.