access DOF values via script

does anybody know how to access the Depth Of Field image effect values? I want to change backgroundblur and foreground.spread" in runtime via script? and tried allot like

GameObject.Find(“camera”).GetComponent(DepthOfField).backgroundBlurSpread = 1;

but i can’t figure out the right way…

Try doing this

private var dof : DepthOfField;
function Start () {
    dof = Camera.main.GetComponent(DepthOfField);
}

Then access foreground- and background blur via:

dof.foregroundBlurSpread = value;
dof.blurSpread = value;

Doing this will go easier on the CPU.

If it’s a focal length based on screen center you want to achieve, here’s an example:

//Create an empty GameObject and assign it to focusPoint in the Inspector
//then assign it to the Object Focus on your Depth of Field script.
var focusPoint : Transform;
function Update () {
    //Focal distance
    	var focalHit : RaycastHit;
    	var focalRay : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2,0));
    	if(Physics.Raycast (focalRay, focalHit, 100)) {
    		focusPoint.position = Vector3.Lerp(focusPoint.position, focalHit.point, Time.deltaTime*10);
    	} else {
    		focusPoint.position = Vector3.Lerp(focusPoint.position, transform.position+Vector3(0,0,100), Time.deltaTime*10);
    	}
    }