I'm doing an FPS game, I have an island surrounded by an ocean, and I'm programming the effect underwater, using fog in the main camera. The problem is that, in the IDE Unity this effect is executed correctly, but when compiling the game, and when executing the .exe file this effect does not play, but in the IDE, as previously commented yes. I do not know what could be failing. The script that I made for this function is the following:
public class UnderWaterEffect : MonoBehaviour
{
//This script enables underwater effects. Attach to main camera.
//Define variable
public int underwaterLevel = 7;
public Material noSkybox;
private AudioSource audioClip;
//The scene's default fog settings
private bool defaultFog;
private Color defaultFogColor;
private float defaultFogDensity;
private Material defaultSkybox;
void Start ()
{
this.audioClip = gameObject.GetComponent<AudioSource>();
this.defaultFog = RenderSettings.fog;
this.defaultFogColor = RenderSettings.fogColor;
this.defaultFogDensity = RenderSettings.fogDensity;
this.defaultSkybox = RenderSettings.skybox;
}
public void ApplyDefaultEffect()
{
RenderSettings.fog = this.defaultFog;
RenderSettings.fogColor = this.defaultFogColor;
RenderSettings.fogDensity = this.defaultFogDensity;
RenderSettings.skybox = this.defaultSkybox;
this.audioClip.Stop();
}
public void ApplyEffect() {
//Set the background color
//Camera.main.backgroundColor = new Color(0.22f, 0.64f, 0.77f, 0.6f);
RenderSettings.fog = true;
RenderSettings.fogColor = new Color(0.22f, 0.64f, 0.77f, 0.6f);
RenderSettings.fogDensity = 0.045f;
RenderSettings.skybox = noSkybox;
this.audioClip.Play(0);
}
}
The above code is called by a trigger, which is a cube that I put on the surface of the ocean, when entering a collision with this cube, the trigger is activated and calls the Camera code of the associated script, the code is as follows:
public class ActivarCamaraAgua : MonoBehaviour
{
public GameObject CameraPlayer;
private void OnTriggerEnter(Collider other)
{
CameraPlayer.SendMessage("ApplyEffect", SendMessageOptions.RequireReceiver);
}
private void OnTriggerExit(Collider other)
{
CameraPlayer.SendMessage("ApplyDefaultEffect", SendMessageOptions.RequireReceiver);
}
}