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
1
Question by keefus · Dec 01, 2010 at 10:21 AM · gameobjectdisableenableselectimage-effects

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.

Comment
Add comment
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

1 Reply

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

Answer by Rennat · Dec 01, 2010 at 10:58 AM

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.

Comment
Add comment · Show 4 · 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 keefus · Dec 01, 2010 at 04:12 PM 0
Share

Awesome help, I managed to get it working with your code, thanks very much.

avatar image CrowbarSka · Jan 25, 2011 at 04:24 PM 0
Share

Where are you finding the script names for the image effects (e.g. Blur, DepthOfField) and the values such as focal.ZDistance, focalZStart? I'd like to be able to tweak these for other image effects.

avatar image keefus · Feb 01, 2011 at 03:28 PM 0
Share

I added the effect to my camera and got the script name from the inspector eg blur would be "BlurEffect" depth of field "DepthOfField" etc, also by opening up the script you can see the variables that are tweakable. Cheers!

avatar image CrowbarSka · Feb 01, 2011 at 05:22 PM 0
Share

Thanks! Easy when you know how... ;)

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

1 Person is following this question.

avatar image

Related Questions

enabling / disabling child objects 1 Answer

Calling setActive(false) on a disabled object? 3 Answers

Bool activate/de-activate on timer C# 1 Answer

If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers

gameobject.setActive(true) || (false) hiccups game for 3 to 5 seconds 4 Answers


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