- Home /
Toggle image effects
Is there a way to toggle image effects of a Main Camera? I want to make it so that in my game there is an explosion and when this is triggered, some of the image effects on the Main Camera are disabled. Also I may wish to enable different image effects. How can this be done?
Answer by SrBilyon · Apr 06, 2013 at 08:31 PM
If you know the type of image effect you want to manipulate, you could enable/disable the effect. For example: If I want to disable a Color Correction image effect:
Camera.mainCamera.GetComponent<ColorCorrectionCurves>().enabled = false;
I get the effect from the main camera and disable it.
I think this is the simplest answer I've ever seen for this. Thank you sir
Thank you @SirVictory. A great lead. Required some small changes so it wouldn't spit out an error in unity 5.2.3f1 . This worked for me:
Camera.main.GetComponent(VignetteAndChromaticAberration).enabled=false;
Hello I am trying to make my player with the tag Player, walk into a cube that is set to IsTrigger and then activate the VignetteAndChromaticAberration component that is attached to the $$anonymous$$ainCamera then yield and WaitForSeconds (2 seconds) and then disable the VignetteAndChromaticAberration component. I feel like i'm getting close but I do not fully understand it and I have tried to search around UA and google.
my script is not working I was just trying to read the manual and scripting API.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.ImageEffects;
public class StartTriggerEffect : $$anonymous$$onoBehaviour {
public VignetteAndChromaticAberration vig;
// Use this for initialization
void Start() {
Camera.main.GetComponent<VignetteAndChromaticAberration>.enabled = false;
}
// Update is called once per frame
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
vig.enabled = true;
yield WaitForSeconds(2);
vig.enabled = false;
}
}
}
Answer by Carvuh · Apr 07, 2013 at 03:14 AM
wouldnt it just be:
var gameObject : GameObject;
var effect_script : SCRIPT_NAME_HERE;
if (Input.GetKeyDown(KeyCode.E)) {
//Or you could assign this to a trigger.
gameObject.GetComponent(effect_script).enabled = false;
}
I believe so.