Search code examples
unity-game-enginescreen-orientationscreen-size

UnityEngine screen size fit every Android device


How can I make my game screen fit every Android device. The problem every answer I find is for 2d. I want for 3d games.


Solution

  • You need two things for a 3D game

    1-) Optimizing the canvas : https://www.youtube.com/watch?v=95q79j0lNYA

    2-) Optimizing the camera angle (if you want it) Optimizing the camera for every screen resolution may not be as easy as canvas. For this, you can take certain standard resolutions with (Get in start Script). Let's set the filed of view of the camera accordingly at Scene Start.

    public class CameraOptimize : MonoBehaviour
    {
      
        // ========
        private void Start
        {
            CameraOptimizer();
        }
    
        private void CameraOptimizer
        {
            if (Screen.height == 2560 || Screen.width == 1440)
            {
                Camera.main.fieldOfView = 65.0f;
            }
            else if (Screen.height == 1920 || Screen.width == 1080)
            {
                Camera.main.fieldOfView = 75.0f;
            }
        }
     
    }