- Home /
Underwater effect question
I have two question actually. First is, how to I make an image effect ( motion blur ) start when I go under water and end 3 seconds after I get out and the second question, how do I add some particle effects like air bubbles only when the player is underwater? Here is my code so far:
var underwaterLevel = 9;
private var defaultFog = RenderSettings.fog;
private var defaultFogColor = RenderSettings.fogColor;
private var defaultFogDensity = RenderSettings.fogDensity;
private var defaultSkybox = RenderSettings.skybox;
var noSkybox : Material;
function Start ()
{ camera.backgroundColor = Color (0, 0.8, 0.8, 1); }
function Update ()
{
if (transform.position.y < underwaterLevel) { RenderSettings.fog = true; RenderSettings.fogColor = Color (0, 0.6, 0.8, 0.9); RenderSettings.fogDensity = 0.1; RenderSettings.skybox = noSkybox; }
else {
RenderSettings.fog = defaultFog;
RenderSettings.fogColor = defaultFogColor;
RenderSettings.fogDensity = defaultFogDensity;
RenderSettings.skybox = defaultSkybox;
}
}
Answer by Bampf · Sep 29, 2010 at 05:05 PM
I seem to recall Unity's tropical island demo had a decent underwater effect. Download the project and try it. You could then take the bits you like and use it in your game.
Answer by Adam Rademacher · Nov 01, 2010 at 08:57 PM
For image effects, you can turn them on and off by flagging 'enabled' like any other component. Therefore,
GetComponent("MotionBlur").enabled = false;
You'll do the same thing when you exit the water, except start a timer in your else condition. So...
private var timer:float = 0; if(transform.position.y < underwaterLevel) { timer = 3; // turn on everything// }
else { timer -= Time.deltaTime; if(timer <= 0) { //turn off everything// } }
Your answer
Follow this Question
Related Questions
How do the camera motion blur exclude layers work? 2 Answers
Blur effect in water 2 Answers
How to use Camera motion blur (oculus rift DK2) 0 Answers
need water 1 Answer
Underwater Effect 1 Answer