Hi All
I’ve done a bit of a search around for a solution but it seems to bring up more questions than answers…
Basically I need a script that applies an image effect (Blur) when the camera moves under a specific height. This is what I have:
var underwater = 75;
var mainCamera : GameObject;
function Start ()
{
var Blur = mainCamera.GetComponent(BlurEffect);
if(mainCamera.transform.position.y < underwater)
{
Blur.enabled = true;
}
else
{
Blur.enabled = false;
}
}
So I select the camera as the variable mainCamera in the inspector.
I have an image effect called BlurEffect applied to the camera.
I’m really not sure why this isn’t working, seems to be pretty straightforward? I don’t get any compile errors, it just doesn’t work.
Thanks
dakka
2
Suggestion, the if statement should be in an update function. Start is only run when the script is initialized.
Thanks dakka, no change though 
Try changing this part
if(mainCamera.transform.position.y < underwater)
to
if(mainCamera.transform.position.y [B]<=[/B] underwater)
Ah! I see what went wrong, you’re using ‘GameObject’ for your camera, try changing it to ‘Transform’.
or attach this script directly to your camera object eliminating the need for the Transform variable all together.
var underwater = 75;
function Update () {
if(transform.position.y <= underwater) {
transform.GetComponent("BlurEffect").enabled = true;
} else {
transform.GetComponent("BlurEffect").enabled = false;
}
}
Thanks RoxSilverFox!
I ended up getting it to work last night on my original code, but yours is much more elegant so I’ll be using it instead.
Thanks again everyone!