0

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);
    }
}
TheGood
  • 23
  • 4
  • Are you sure that your game is running the same _Quality_ settings as the editor? –  Apr 27 '19 at 00:15
  • Check that you've got a reference to the Shader attached to a gameobject or included in project settings, Unity strips out things it thinks are not used, as described here. https://stackoverflow.com/questions/55660837/unity-post-processing-postprocesseffectrenderer-shows-in-editor-but-not-in-build/55660838#55660838 – Jamie Gould Apr 27 '19 at 01:27
  • @MickyD The graphics game on the final build and the unity editor is Ultra. – TheGood Apr 27 '19 at 01:28
  • @JamieGould The problem is that for this work I have not created shaders, will that be why? Or on the contrary, can it work without shaders? – TheGood Apr 27 '19 at 02:01
  • @TheGood It will be using the default shader if you've not written your own, you could try just putting a standard cube in the scene using the same material and default shader as your object with the effect and see if that fixes it. If it does it because something is being stripped out by Unity on build. You can also try creating a development build with the console enabled and see if it complains about anything missing. – Jamie Gould Apr 27 '19 at 02:08
  • @JamieGould why would it be a _"shader"_ problem when it works for the OP perfectly in the Editor –  Apr 27 '19 at 07:25
  • @MickyD Unity sometimes strips them off -> in a build not all shaders are included that are present in the editor. In the graphic settings you can try to explicitly include the according shader. `Settings` -> `Graphics` -> `Allways Include Shaders` – derHugo Apr 27 '19 at 09:05

0 Answers0