Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Caiuse · Apr 18, 2011 at 06:56 PM · getcomponentimage-effectsdof

Changing Image Effect 'Depth Of Field' in run time

I'm having trouble with accessing the 'Depth of Field' image effect that's placed on the main camera in my scene.

I'm trying to change two things the "Focus On Target" and also the effect amount so I can fade it completely away. (I'm aware that there isn't a current Effect Amount variable so please could someone explain how I could go about adding this to the depth of field effect)

Any ideas? Cheers - C

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jooki-2 · Jun 22, 2011 at 06:50 PM 0
Share

does anybody know how to access the rest of the dof values? i want to change "backgroundblur and foreground spread" via script?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Apr 18, 2011 at 08:59 PM

I think you would just assign 'ObjectFocus' to whatever object you want to focus on, something like

Camera.main.GetComponent(DepthOfField).objectFocus = myCoolObject; // or myCoolObject.transform?

and the amount of effect seems to be 'focal size' (except at zero it's more intense) so maybe:

if (amount > 0)
{
  Camera.main.GetComponent(DepthOfField).enabled = true;
  Camera.main.GetComponent(DepthOfField).focalSize = amount;
}
else
  Camera.main.GetComponent(DepthOfField).enabled = false;
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Caiuse · Apr 18, 2011 at 11:41 PM 0
Share

Thanks great work on the Effect Amount makes a nice quick fix, one problem Object Focus is not found :/

avatar image DaveA · Apr 18, 2011 at 11:49 PM 0
Share

try objectFocus

avatar image Caiuse · Apr 19, 2011 at 11:58 AM 0
Share

GetComponent(DepthOfField).focusOnThis Is the paramater

avatar image DaveA · Apr 19, 2011 at 05:10 PM 0
Share

Really? I just coded something almost exactly like this yesterday, I thought it was objectFocus...

avatar image Caiuse · Apr 24, 2011 at 01:38 PM 0
Share

$$anonymous$$aybe i'm using some outdated Unity assets, it's focusOnThis or objectFocus depending on your unity assest version for anyone who is trying this.

avatar image
0

Answer by MaxvH · Dec 08, 2012 at 04:08 AM

 I don't know what Unity version you guys are using, but there is no "Depth Of Field" script in Unity 3.5 or Unity 4. There is a "Depth Of Field (34)", a "Tilt Shift", and a "Depth Of Field (Scatter)".  Is there something I'm missing, like a built in script or something?  Or did you just write "DepthOfField" because different people use differnet scripts?  I'm mentioning this not because I'm that jerk who corrects people or anything but because the script is not working for me and I am wondering if there is an obvious reason why.  The "amount" in my script is the value of a knob from the iGUI user interface plugin.  Here is the script I have:

 

    public void knob1_ValueChange(iGUIKnob caller){
             if (knob1.value > 0)
             {
                 Camera.main.GetComponent(DepthOfField34).objectFocus = gameObject.transform;
                 Camera.main.GetComponent(DepthOfField34).enabled = true;
                 Camera.main.GetComponent(DepthOfField34).focalZDistance = knob1.value;
             }
             else
                 Camera.main.GetComponent(DepthOfField34).enabled = false;
         }


So what I'm wondering is, is there something obviously wrong with my script, or is this just because my version of unity is too new? And yes I did add the component to the main camera and I did use the right variables (I think).

Thanks/hope my comment was somewhat helpful! -Max

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Problems with Depth of Field, anyone else? 3 Answers

What is the right way to modify depth of field focal distance via script at runtime? 1 Answer

Anti-Aliasing causes post processing effects to flip. 3 Answers

Documentation on the bloom filter 0 Answers

List error c# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges