• 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 8r3nd4n · Sep 12, 2011 at 07:53 AM · cameraimage-effects

Change cameras image effects with button press

HI all,

New to Unity and trying to get a script that will allow image effects attached to the main camera to be cycled through with button presses. At the moment I have different effects that are attached to different cameras that I can cycle through(the cameras) but it would be more efficient to have them all on the one camera object so that when I do modifications to the camera, I only have to do it once. I have looked at the following reference: Code:

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {
     void Update() {
         OtherScript otherScript = GetComponent<OtherScript>();
         otherScript.DoSomething();
     }
 }

but cant seem to work it out. I have a BloomEffect and a EdgeDetectEffect script that I want to use. Any advice

Cheers

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by asafsitner · Sep 12, 2011 at 09:54 AM

I had a similar problem. The first thing you need to do is move all the Image Effects scripts that you use to \Assets\Plugins folder (make one if you don't have it already). That way the .js files can be accessed from the .cs files (for instance, c# won't recognize BloomAndLensFlares as a class until you do and so you can't pass it as a component to the OtherScript variable). After you've done that, all you have to do is indeed store BloomAndLensFlares (or any other image effect for that matter) in a variable (preferably cache it at the Start() or Awake() methods for more efficient code)and later change the 'enabled' property of the component as needed. For example:

 using UnityEngine;
 using System.Collections;
 using Assets.Scripts;
 
 public class ToggleBloom : MonoBehaviour 
 {
     private BloomAndLensFlares _bloomToggle;
 
     void Start()
     {
         _bloomToggle = transform.GetComponent("BloomAndLensFlares") as BloomAndLensFlares;
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(Input.GetKeyDown("space"))
         {
             _bloomToggle.enabled = !_bloomToggle.enabled;
         }
     }
 }

Now you'll probably want to store the effects in an array and iterate over them as you press the button, but that's the general idea.

Hope that helps!

Comment
Add comment · Show 7 · 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 asafsitner · Sep 12, 2011 at 10:12 AM 0
Share

Or maybe enumerate them.

avatar image 8r3nd4n · Sep 12, 2011 at 10:39 AM 0
Share

Cheers, Works a treat.

Yeah, I admit I was lost with why it wouldnt recognize the c# classes.

Using that class you created, am I correct in that I can access all variables/properties of the BloomAndLensFlare class? So to use a button press to change the intensity would be something like:

    if(Input.Get$$anonymous$$eyDown("I"))
    {
         _bloomToggle.bloomIntensity++;
    }

Thanks Again

avatar image asafsitner 8r3nd4n · Sep 12, 2011 at 09:16 PM 0
Share

Apologies for the late response. Yes, you are correct in that you can access all the properties of the BloomAndLensFlares class. You might also want to mark the answer as accepted if/when it's satisfactory so it won't appear on the 'unanswered' list.

avatar image 8r3nd4n 8r3nd4n · Sep 13, 2011 at 02:23 AM 0
Share

Thanks again, got it workin just as I wanted.

Also, can't for the life of me work out how to mark the question answered. Any help?

avatar image asafsitner 8r3nd4n · Sep 13, 2011 at 07:40 AM 0
Share

Should be a little circle with a 'v' on it on the left side, where the little hands are. If you click it it should turn green and that's it. Been a while since I asked a question here ^^'

avatar image Mehrdad995 · Nov 04, 2013 at 11:39 AM 0
Share

moving to plugins folder helped me allot. thanks :D

avatar image kiko-sweezy-kiko · May 22, 2017 at 03:17 PM 0
Share

i moved to plugins but still gives me same error what to do? is there a way to write the same script in javascript im sure i wont have this problem

avatar image
2

Answer by mattcscz · Jan 04, 2015 at 12:40 PM

If you look at the script they are using namespaces, so you are able to do "using UnitySampleAssets.ImageEffects;" Then you can correctly reference the BloomAndFlares without any extra hastle.

Example:

 using UnityEngine;
 using System.Collections;
 using UnitySampleAssets.ImageEffects;
 
 public class ChangeCamEffects : MonoBehaviour {
 
     public GameObject MainCam;
 
     public void DoStuff() {
 
         MainCam.GetComponent<BloomAndFlares> ().bloomIntensity = 1;
 
     }
 
 }


Hope this helps.

Comment
Add comment · Show 3 · 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 mattcscz · Feb 09, 2015 at 03:28 PM 0
Share

I had the issue the other day, and there was no up-to-date answer. I'm sure this would help people having the issue now, giving comments like yours won't =)

avatar image YK9 · Jul 23, 2015 at 01:40 PM 0
Share

Thank you. I was trying for several hours yesterday trying to get access to my shader scripts, and simply adding the namespace like you suggested did exactly what I wanted.

avatar image admasto95 · Jul 23, 2017 at 11:20 AM 0
Share

I can't seem to access the Effects like that :(

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Ngui Camera and Image effects 0 Answers

Unity 5 image effects for multiple cameras 1 Answer

Image effects do not work when rendering with multiple cameras 0 Answers

Making layers ignore Image Effect 0 Answers

Detect object in image and change background of image 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