x


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?

more ▼

asked May 09 '12 at 03:33 PM

aljndrrr gravatar image

aljndrrr
20 5 10 15

Probably related to the order in which scripts are compiled. See http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html.

May 09 '12 at 03:37 PM Graham Dunnett ♦♦
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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#?

more ▼

answered May 09 '12 at 03:57 PM

bompi88 gravatar image

bompi88
741 2 5

DepthOfField.js is one of the Unity Pro Image Processing scripts, and it is supplied as a .js :)

May 09 '12 at 05:24 PM aljndrrr
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 09 '12 at 03:42 PM

GC1983 gravatar image

GC1983
540 18 33 44

I can't seem to find the button for the compilation order, I'm using Unity 3.2

May 09 '12 at 05:09 PM aljndrrr
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x11

asked: May 09 '12 at 03:33 PM

Seen: 340 times

Last Updated: May 09 '12 at 05:24 PM