- Home /
turn image effect on/off at a specific area
hey everyone. so, here's my problem: If got an character moving with fps Controller from the unity standard assets on a straight plane. area a -to- b should have the pro image effect "glow", area b -to- c should be without it.
a=========b====c I with effect I I not I
the ground has a self illumine material, and the glow effect is attached to the main camera of the fps view. I'm a beginner at scripting, how can i turn the effect now on/off?
Answer by hijinxbassist · Jun 14, 2012 at 06:44 PM
You would get that component on the main camera and set enabled to false.
Camera.main.GetComponent(GlowEffect).enabled=false;
@hanso So when you hit point 'b'(however you deter$$anonymous$$e that event, by trigger or what-have-you) just say that line to turn the effect off. If you want to turn it on again, set enabled back to true (enabled refers to the check box next to the script name in the inspector). Heres an example with trigger:
//Trigger for the B-C section
function OnTriggerEnter(other:Collider)
{
if(other.name=="Player") //Player entered the trigger
Camera.main.GetComponent(GlowEffect).enabled=false;
}
Can you put your comment in the comment section ins$$anonymous$$d of the answer box, helps ppl sift through the answers better. You can just delete it at this point tho, since i read it :)
hey! thank you again! so, this is how i made it now: at the point B, I set up an box collider and put your script in it. It's working now - when my player01 touches it, the effect is turned off.
But, i get this warning in the console:
Destroying object immediately is not permitted during physics trigger and contact callbacks. You must use Destroy ins$$anonymous$$d. UnityEngine.Object:DestroyImmediate(Object) GlowEffect:OnDisable() (at Assets/Standard Assets/Image Effects (Pro Only)/GlowEffect.cs:69) UnityEngine.Behaviour:set_enabled(Boolean) triggerding:OnTriggerEnter(Collider) (at Assets/triggercameffect.js:6)
2nd. If it's not a huge hardcore code, is it possible to turn it off a little more "gently". like the 3dsound, if my player walks through the trigger, the effect turns off slowly
Hmm...you know i did not test it, but lerping one(or all) of the values to ease the effect out will be better anyway. For the "gentle fade" you will need to Lerp some of the values down to 0. This is quite a bit different from the original question now, so i suggest doing a search for previous questions about Lerp. Heres a good example of http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html>lerp, you will change the functions parameters to floats and ins$$anonymous$$d of Vector3 you will use $$anonymous$$athf.
The basic idea is to gradually decrease a variable(float) over the course of a specified time(t). In this case the vars are glowIntensity, blurIterations, and blurSpeed. It takes some time to get use to using Lerp(or Slerp for longer fades), but once you get the hang of it youll be lerping all over the place :) As for the enabled portion,do away with it completely. Also store the starting values in some vars, that way if you want to lerp the effect back in you will have those values handy.
@hanso Heres a link to a post i just did for this same effect. http://answers.unity3d.com/questions/269791/delta-component.html>Fade in float values using $$anonymous$$athf.Lerp.
Your answer
Follow this Question
Related Questions
Glow single Object 1 Answer
ImageEffects and multiple camera depths 0 Answers
Selective glow through a multi camera setup with a bloom effect 0 Answers
Texture masked glow post effect 0 Answers
Rune glow effect on stones? 1 Answer