Accessing DepthOfField.js from C# Script?

I have a camera that has the DepthOfField.js attached to it. And I want to access to this component from another object using on a C# script.

Camera.mainCamera.gameObject.GetComponent(DepthOfField).focusOnThis = gameObject;

But I get and error on the DepthOfField type (is unknown), also if I try “DepthOfField”, I get the same error.

Any suggestions?

First of all, the code you post here is “Java Script” (Unity Script). The following code should work in your C# script, if the order in which scripts are compiled is set up right.

Camera.mainCamera.gameObject.GetComponent<DepthOfField>().focusOnThis = gameObject.

Why not port the DepthOfField.js to C#?

click on your C# script and in the upper right part of its inspector, youll see compilation order. Click on that, and add that script to the list. Doesnt matter its order. And hit apply. That most likely will solve your issue.