enable/disable image effects in code

I currently have a game object selectable by the user and I'm trying to figure out how to enable depth of field when selected and disable when its not.

Any help would be appreciated.

First setup a way to talk to the DepthOfField component from your gameobject

public mainCamera : GameObject; // set this to the main camera in the inspector
private dof : DepthOfField;

function Start () {
    var dof : DepthOfField = mainCamera.GetComponent(DepthOfField);
}

then either tweak the settings

function Focus () {
    // set the focus settings, I'm making these numbers up
    // but this should be a decent starting point.
    dof.focalZDistance = 0;
    dof.focalZStart = 0;
    dof.focalZEnd = 1000;
}

function Blur () {
    var distanceToFocusedObject = // get the distance to the focused object
    // set the focus settings
    dof.focalZDistance = distanceToFocusedObject;
    dof.focalZStart = distanceToFocusedObject - 5;
    dof.focalZEnd = distanceToFocusedObject + 5; // I'm still making these numbers up
}

or toggle enabled

function Focus () {
    dof.enabled = false;
}

function Blur () {
    dof.enabled = true;
}

I haven't tested any of this code but I think the approach is valid.

Also I bet animating `focalZStart` and `focalZEnd` in the `Focus` and `Blur` functions would look pretty cool.