Unity Andriod screen edge visual glitch
Hi all,
I've been working on a cross-platform game in Unity and am really stuck with a baffling visual glitch for some Android devices. Basically, on some devices, the left and right side of the screen, instead of becoming cropped or pillarboxed (there is a script on the MainCamera to do this to maintain the aspect ratio), become glitchy, "wrapped" versions of the content on screen. This image is an example of the issue
There is a thin black line on each side, but then a lot of weird effects!
This is the code on each MainCamera which is supposed to be maintaining the aspect ratio:
public class CameraCrop : MonoBehaviour
{
// Set this to your target aspect ratio, eg. (16, 9) or (4, 3).
public Vector2 targetAspect = new Vector2(16, 9);
Camera _camera;
void Start()
{
_camera = GetComponent<Camera>();
UpdateCrop();
}
// Call this method if your window size or target aspect change.
public void UpdateCrop()
{
// Determine ratios of screen/window & target, respectively.
float screenRatio = Screen.width / (float)Screen.height;
float targetRatio = targetAspect.x / targetAspect.y;
if (Mathf.Approximately(screenRatio, targetRatio))
{
// Screen or window is the target aspect ratio: use the whole area.
_camera.rect = new Rect(0, 0, 1, 1);
}
else if (screenRatio > targetRatio)
{
// Screen or window is wider than the target: pillarbox.
float normalizedWidth = targetRatio / screenRatio;
float barThickness = (1f - normalizedWidth) / 2f;
_camera.rect = new Rect(barThickness, 0, normalizedWidth, 1);
}
else
{
// Screen or window is narrower than the target: letterbox.
float normalizedHeight = screenRatio / targetRatio;
float barThickness = (1f - normalizedHeight) / 2f;
_camera.rect = new Rect(0, barThickness, 1, normalizedHeight);
}
}
}
If anybody has encountered a problem like this before, I'd really appreciate the help.
Could you solve this issue? I'm having the same now, trying to fix it...
Your answer
Follow this Question
Related Questions
Force top black bar on Android devices 1 Answer
Resolution Of Android and IPhone. 1 Answer
Object shrinks from different screen resolution 0 Answers
Unity built game resolution issue 1 Answer
Terrain - white flags problem 0 Answers