Home > Mobile >  In Unity Android build, the black background flash blue light when make the game inactive then awake
In Unity Android build, the black background flash blue light when make the game inactive then awake

Time:12-22

To make the fit different screen resolutiosn, I added code below to add black sides when the screen resolution is not the same. It works fine when I open the game in android. But when I sleep the phone, or switch to another app and switch back, the black side start to flash with blue color. Any suggestion what can be the reason of this? Or is there a better way to fix screen resolution? Thanks!

private void Awake()
{
    FitCamera(Camera.main);
}

public void FitCamera(Camera camera)
{
    if (DevelopRate <= ScreenRate)
    {
        camera.rect = new Rect(0, (1 - cameraRectHeightRate) / 2, 1, cameraRectHeightRate);
    }
    else
    {
        camera.rect = new Rect((1 - cameraRectWidthRate) / 2, 0, cameraRectWidthRate, 1);
    }
}

CodePudding user response:

Try attach this script to your camera, it will clear the whole screen before rendering.

public class ClearScreen : MonoBehaviour
{
    void OnPreRender()
    {
        GL.Clear(true, true, Color.black);
    }
}
  • Related