I am trying to toggle visual/image effects on the main camera on or off, but with no luck. I’ve scoured the forums and seen posts regarding the similar.
I have my effects all on the main camera, as recommended. Such as Bloom and Blur.
I’ve read I need to create and attach a script such as the following to my Main Camera to then be able to use the AC method – Object > MainCamera > ??? > Send Message > Turn On or Turn Off.
void TurnOnEffect ()
{
this.GetComponent <Bloom>().enabled = true;
}
void TurnOffEffect ()
{
this.GetComponent <Bloom>().enabled = false;
}
What other code do I need around the above as Unity doesn’t like this as it is? I know this isn’t a general unity programming forum, but im hopefully somebody can help my with how to get this working with AC. Hope do I tell then the AC script to Turn On or Off each specific image effect?
I found the AC Light Switch trigger fantastically easy to use, I hoped that triggering camera image effects was going to be just as easy.
Thanks
Comments
To call the functions in your script, you would have to set your Message to send to Custom, and then enter in the name of the function (e.g. TurnOnEffect) into the Method name box.
("CameraEffect" is the name of the script. Be sure to add "using UnityEngine.PostProcessing;" I wasn't able to use <PostProcessingBehaviour> without it)
I'm sure there's a lot wrong with this code, or it has some redundant lines, but it works! :P
Your code there will work to turn on or off the post processing stack v1. Though it'll disable the whole thing. I've worked with making options UI for the Post processing stack v1 before, but the ways to change the settings of particular effects through code is a pain in the ass though.
I used to have a post processing profile switcher, and I changed some effects based on some static settings I had.
//...........................then inside the class
public PostProcessingProfile NewProfile;
void Start()
AntialiasingModel.Settings tempSettings = newProfile.antialiasing.settings;
newProfile.antialiasing.settings = tempSettings;
To avoid messing with the Profile asset it's recommended to instantiate a runtime copy (like I show above).
Enabling or disabling individual effects is not as hard (they have an "enabled" property).
But, most of the fx in V1 use a dedicated class to contain the settings for that effect. If you want to change the settings for the effect (rather than just turn it on or off) then you have to replace the whole settings "container" for that effect. That's why I created the settings container and changed the settings in this object, and only then assigned the settings container to the effect.
You could replace the parts where I use my own globals and use AC's global variables instead (here's the tutorial showing how to use them in code). but it would basically look something like: