Detect device and adjust screen

Hello everybody,

I found myself in a situation where my game does not accurately fit into the screen on all devices (specifically, Desktop + iPhone + iPad but I am guessing the situation with Android is much more segmented).

So, my first hunch was to do a device testing function, and adjust the distance of the camera accordingly (this is a fixed-position camera, looking at the game field).

While trying to answer my own question, I found these links on the subject:

  1. iPhone.generation - detect device + generation. Problematic solution, new devices will be left out.
  2. SystemInfo.deviceType - only helps in differentiating between Handheld / Desktop
  3. Application.platform - same problem as above, differentiate between iPhone player and desktop.
  4. Platform Dependent Compilation - compile time directives, same problem.
  5. Screen

My questions are:

  1. Is this the correct approach? Should I use device detection or screen size detection?
  2. Did I miss any function that lets me simply ask “Is this an iPhone of ANY generation?” or “Is this an IPad of any generation?”

Thanks in advance.

I think you should go for screen size detection, because a device can have different resolution. So you have to generalize your code according to your screen and current resolution and also adjust your camera accordingly.

I think this can be solved by Manipulating Camera Aspects Manually .
i faced this problem too, and i fixed it by an script which could Set the Appropriate Aspect for each device .
you need to just change these values i think :

1 - Camera.main.aspect = (Screen.currentResolution.width / Screen.currentResolution.height);

  • just this simple piece of code helped me fit each of my game scenes for any Android devices .