Enable/Disable Image Effects on Camera using script

Hi everyone,

So here is a newb question :
How do I enable or disable an image effect on a camera using a script.

There are explosions in my project. My goal is to use use the Noise effect for small moment when something explodes.

Thanks :wink:

scripts have an inherent ‘enabled’ variable that can be set to true or false.

here’s some simple javascript that you can add to your camera:

function NoiseToggle () {

	var noise_script = gameObject.GetComponent(NoiseEffect);
	noise_script.enabled = !noise_script.enabled;	
}

function NoiseBurst(BurstLength){
	
	this.NoiseToggle();
	Invoke("NoiseToggle", BurstLength);	
	
}

NoiseToggle
This function will get the NoiseEffect script component from the game object, and then set the ‘enabled’ variable to its opposite. You can call this to turn on and off the noise at any time you like.

NoiseBurst
This function toggles the NoiseEffect immediately, and then again after BurstLength seconds.

Call the camera’s NoiseBurst when an object explodes, with the length of the noise effect as a parameter.

Thank you very much for the answer.
I thought it would work but actually Unity doesn’t find NoiseEffect as a component.

"Unknown identifier: 'NoiseEffect'."

Just an aside, could you have two cameras and have effects on one only, and switch them at appropriate times?

AC

Did you add the NoiceEffect script to the camera (you need to have Pro Standard Assets included to the project)?

yes I did .

It works with bloom and flares
maybe you should try “Noise” instead of “NoiseEffect”

After a bit of testing it seem that you can only access the c# image effects from a c# script and java from java… weird huh?

That’s not the case; it’s a matter of script compilation order. http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html (P.S., Unity doesn’t use Java.)

–Eric

If you want to enable or disable Image Effect Script you should add this
using UnityStandardAssets.ImageEffects;

In Unity 5 or above.

That’s not correct, and has nothing whatsoever to do with enabling/disabling image effects. Certainly not worth necroing a 7-year-old thread.

–Eric

1 Like