- Home /
How To Activate/Deactivate Image Effect On Keypress?
Hello. I currently am trying to implement a simple enable/disable mechanic for my main cameras image effects.
I have this script here but it gives me errors and i cannot test. All i am trying to do is be able to toggle the effect via pressing a key on the keyboard, kind of like in some games you press "N" for nightvision or whatever and can press it again to turn it off.
Any help is appreciated.
Also, this is part of Aubergines Post Process pack so maybe the folder location is causing the problem when i just try to put the name in the script? Do i need to put like "Assets/Aubergines/Effect/"the effect"?
public var myEffect : PP_SobelOutlineV3;
function Start ()
{
myLight = GetComponent(PP_SobelOutlineV3);
}
function Update ()
{
if(Input.GetKeyUp(KeyCode.Space))
{
myLight.enabled = !myLight.enabled;
}
}
Heres the error code:
Assets/Deactivate.js(1,23): BCE0018: The name 'PP_SobelOutlineV3' does not denote a valid type ('not found').
Answer by Johat · Apr 20, 2016 at 07:11 AM
I'm not familiar with the Image Effects pack you're talking about. However, what language is that pack written in?
If it's written in C# and you're trying to access it in JavaScript, you won't be able to see it and will get the error you see.
A handy trick to get around this is to put the Image Effects pack inside the Standard Assets folder (if it doesn't exist, just create one Assets/Standard Assets/THE_PACKAGE).
Scripts in Standard Assets always get compiled first, so when it comes to compiling your regular scripts, they should be able to see them.
Answer by faizidp · Apr 20, 2016 at 09:07 AM
void Update(){
if(Input.GetKeyDown(KeyCode.A)){
this.GetComponent < ImageEffect >().enabled=false; } }
Attach this script to camera and change "ImageEffect" to the effect name you are using!
Your answer
Follow this Question
Related Questions
How to activate/deactivate a component(Animator) when a specific game object was activated 0 Answers
Deactivate an object - and all scripts in that object deactivated? 1 Answer
activate object on key press only, otherwise always deactivated! 2 Answers
2D Animation does not start 1 Answer
Problems deactivating a script. 1 Answer