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
2
Question by BitGlitch · Mar 10, 2015 at 02:47 PM · cameradynamicdepth of field

Referencing DOF in a script? (Unity 5)

Hey guys, I am trying to make a script to change the object that DOF focuses on dynamically within my script. Its working smoothly other than the fact I can't actually reference the DepthOfField script within my script. Any suggestions?

 using UnityEngine;
 using System.Collections;
 
 public class DOFCameraFocusScript : MonoBehaviour {
 
     public float maxFocusDistance = 1000;
 
     public GameObject camera;
     
     public Component depthOfFieldScript;
 
     // Update is called once per frame
     void Update () 
     {
         if (camera == null)
         {
             camera = Camera.current.gameObject;
         }
 
         depthOfFieldScript = camera.GetComponent <DepthOfField> ();
 
         RaycastHit hit;
 
         if (Physics.Raycast(camera.transform, camera.transform.TransformDirection, out hit, maxFocusDistance))
         {
             DepthOfField.focalTransform = hit.collider.gameObject;
         }
     }
 }
 
Comment
Add comment · Show 2
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 Owen-Reynolds · Mar 10, 2015 at 03:41 PM 0
Share

Error on line 26? That's a basic program$$anonymous$$g problem. Read about types vs. variables.

avatar image BitGlitch · Mar 10, 2015 at 08:57 PM 0
Share

If you would read the title: Line 26 does give an error, but that is not the problem I'm experiencing. The problem ( if you are using unity 5 and have the DOF script) is that even when I use GetComponent(), it is not able to find the script (Even though the script is called "DepthOfField"). I just realized it does say DepthOfField in line 26, but I tried doing that after having depthOfFieldScript there in the first place.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Mar 10, 2015 at 07:00 PM

yea line 26.

DepthOfField is a class but it's just a class.

its not the actual cameras depth of field it's just a definition of what depth of fields are and how you can change them. This is the blueprint for ford mustangs for example not your ford mustang.

Something like camera.main.depthoffield is how your going to get the actual cameras depth of field.

Comment
Add comment · Show 2 · 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 BitGlitch · Mar 10, 2015 at 08:28 PM 0
Share

Thanks for the explanation, but that does not work. Just tried it.

avatar image BitGlitch · Mar 10, 2015 at 08:29 PM 0
Share

Actually, I need to activate Unity 5's DOF class because I want to assign the focus target on that script. Thanks for trying to help though.

avatar image
0

Answer by alsharefeeee · Nov 01, 2015 at 01:24 PM

Declare: public UnityStandardAssets.ImageEffects.DepthOfField dof;

Awake: dof = GetComponent();

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
avatar image
0

Answer by Riacosta · Jan 25, 2016 at 12:29 PM

You need to copy the script to your assets folder (or any subfolder in it) and then reference the namespace UnityStandardAssets.ImageEffects. Then you'll be able to reference the script.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to dynamically assign a camera? 0 Answers

2.5d Side Scroller Dynamic Camera Zoom 1 Answer

game grid generating whle in camera view ? 3d game scene) android 3 Answers

Getting the Camera to Match the Size of the canvas with dynamically added UI elements 1 Answer

Post Processing Depth of Field in 2D 0 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