I have made an app (Runner, from the tutorial), when I built the game and ran it on my Nexus 7 tablet, the default ‘powered by unity’ splash screen appears for a second or two, then starts to flicker (like a strobe) on and off. I decided to change the splash screen to a custom made one (in paint) and that consisted of the same problem?
I have the exact same problem and I am also using a Nexus 7. The strange thing is, I have previously built and played the game just fine on my tablet. Since then I have added several features and updated my Android SDK tools, so I’m not sure exactly what I did to create the problem or whether the problem was even created by something that I did in my Unity project.
I’m going to create a new test project to see if that is able to build correctly.
If anyone has had similar issues, or knows how to fix this, then any help would be greatly appreciated.
I am using an Orthographic Camera and I was setting the orthographicSize to 0.
In order to keep everything the same size when the Screen.orientation changes, I needed to change othographicSize when the orientation changes. To do so I created a scalar to change the orthographicSize when the screen’s orientation is Landscape.
My original code to calculate the Orientation Scalar was:
fOrientationScalar = Screen.width / Screen.height;
The problem was that because Screen.width and Screen.height are readonly variables, fOrientationScalar was set to 0.
Changing the code to this solved the problem:
float fWidth = Screen.width;
float fHeight = Screen.height;
fOrientationScalar = fWidth / fHeight;
tl;dr
If you are using an Orthographic Camera, make sure that you are not inadvertently setting the orthographicSize to 0.
If you need to calculate a value using Unity’s readonly variables, store their values in your own temporary variables first and then use the temporary variables to do the calculation.
The problem likely isn’t the fact Screen.width and Screen.height are read only,
the problem is the fact they’re integer.
And dividing 2 integers produces an integer so on a phone 1080 / 1920 = 0.56 gets truncated to 0.
You fixed this unintentionally by converting width to a float!
You could also have solved it with this:
fOrientationScalar = ((float) Screen.width) / ((float) Screen.height));