Screen width "not correct" in all resolutions
I have a menu on the canvas which I hide by moving the menu off of the canvas to the right. To do so I am using the following:
private void Show(bool active)
{
if (active)
{
menuRectTransform.SetLeft(0);
menuRectTransform.SetRight(0);
}
else
{
menuRectTransform.SetLeft(Screen.width);
menuRectTransform.SetRight(-Screen.width);
}
}
The canvas scaler is as follows
When I test on a device with a resolution of 1920x1080 or greater it works fine. The menu hides and shows as it should. However, when I test on a smaller device the menu does not hide completely.
When I debug it the screen width is 854px. When the menu hides it is still visible on the screen and I need to move it to 1920px to be completely off the screen.
Ok so easy fix, bit of a small hack, not my proudest moment, but this works in the editor:
private void Show(bool active)
{
//Debug.Log("Show NML Menu: " + active);
if (active)
{
menuRectTransform.SetLeft(0);
menuRectTransform.SetRight(0);
}
else
{
bool widthSizeLimitation = false;
if (Screen.width < 1920)
widthSizeLimitation = true;
menuRectTransform.SetLeft(widthSizeLimitation ? 1920 : Screen.width);
menuRectTransform.SetRight(widthSizeLimitation ? -1920 : -Screen.width);
}
}
After testing on an actual device (Width 854px) the menu still does not hide completely.
Does anyone know why this is? Am I missing something silly here? Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612220820im_/https://answers.unity.com/themes/thub/images/avi.jpg)