- Home /
Underwater effects error?
I run my game, with a character controller and everything, and it says to fix all the errors in the compiler. I look in the compiler and I see this:
'Assets/Scripts/UnderwaterEffects.js(23,46): BCE0022: Cannot convert 'UnityEngine.GameObject' to 'float'.
What is this and how can I fix it? and there is no water in my scene...
Windows 7 64-bit
Post the script here - it's an error in line 23 of the UnderwaterEffects.js, but we need to see it to help you. All scripts in the Assets folder and subfolders must compile ok - even those you're not using.
var waterLevel : float; var uAudio : AudioClip; var aAudio : AudioClip;
var uColor = Color(1,1,1,1); var uDensity = .05;
var aColor = Color(1,1,1,1); var aDensity = .008;
var waterSurface : Renderer; var underwaterSurface : Renderer;
private var below = false; private var glow : GlowEffect; private var blur : BlurEffect;
function Awake() { if(!waterLevel) { water = FindObjectOfType(Water); if(water) waterLevel = water.gameObject; } aColor = RenderSettings.fogColor; aDensity = RenderSettings.fogDensity;
glow = GetComponent(GlowEffect);
blur = GetComponent(BlurEffect);
if( !glow || !blur )
{
Debug.LogError("no right Glow/Blur assigned to camera!");
enabled = false;
}
if( !waterSurface || !underwaterSurface )
{
Debug.LogError("assign water & underwater surfaces");
enabled = false;
}
if( underwaterSurface != null )
underwaterSurface.enabled = false; // initially underwater is disabled
}
function Update () { if (waterLevel < transform.position.y && below) { audio.clip = aAudio; audio.Play(); RenderSettings.fogDensity = aDensity; RenderSettings.fogColor = aColor;
below = false;
glow.enabled = !below;
blur.enabled = below;
waterSurface.enabled = true;
underwaterSurface.enabled = false;
}
if (waterLevel > transform.position.y && !below)
{
audio.clip = uAudio;
audio.Play();
RenderSettings.fogDensity = uDensity;
RenderSettings.fogColor = uColor;
below = true;
glow.enabled = !below;
blur.enabled = below;
waterSurface.enabled = false;
underwaterSurface.enabled = false;
}
}
Thats my Underwatereffects.js. I barely understand this...
Line 23:
if(water) waterLevel = water.gameObject;
Answer by subhendus · Feb 15, 2012 at 11:07 AM
waterLevel is float and gameObject is an object.
This has been discussed in Unity Forum and seems it happened for project conversion.
So the following will fix it. if(water) waterLevel = water.gameObject.transform.position.y;
Answer by Minion54847 · Dec 23, 2011 at 12:51 PM
just switch the lower case g on gameObject to a capital so its GameObject
Answer by aldonaletto · Oct 04, 2011 at 02:34 AM
The beginning of Awake() is wrong. I don't know how it was before, but with some changes it may work - or at least stop producing compiler errors (any script with errors prevents the whole project from work, even if you don't ever use it).
I believe the modifications below are enough: add a water GameObject variable and modify the first if in the Awake function:
... private var blur : BlurEffect; var water: Water; // declare this variable
function Awake() { // and modify the first "if" of Awake to this: if (!water) { // if water not set at the Inspector... water = FindObjectOfType(Water); // try to find Water object // if found, set waterLevel to the water position if (water) waterLevel = water.gameObject.transform.position; } ...
Answer by LouisB · Jun 03, 2012 at 08:06 PM
switching the case on the G cleared the error for me. Not sure how to test if the script is still working. The next error was something about not supporting UnityEditor, so I just commented those two lines out in the file UpdateTreeColors
Answer by ramp · Nov 17, 2014 at 01:23 PM
Hi,
You can use the following code instead of code line 23.// if(water) waterLevel = water.gameObject;
if (water) waterLevel = water.transform.position.y;
Thanks Ram
Your answer
![](https://koobas.hobune.stream/wayback/20220612234211im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Overlapping Unity Players w/ Transparency 1 Answer
Underwater effects for rivers 0 Answers
Problem quitting app on Win7 64bit 1 Answer
VCRuntime errors with Universal Windows Platform, but it runs within Unity 0 Answers
Problems with 64-bit systems 0 Answers