How can I code my game to work on every resolution of Android devices? (with Unity)

前端 未结 6 1365
梦毁少年i
梦毁少年i 2021-01-30 19:12

I have a game what I made in 480x320 resolution (I have set it in the build settings) in Unity. But I would like to publish my game for every Android device with every resolutio

6条回答
  •  情书的邮戳
    2021-01-30 19:20

    Here is my script for scaling the ortographic camera in 2D games

    public float screenHeight = 1920f;
    public float screenWidth = 1080f;
    public float targetAspect = 9f / 16f;
    public float orthographicSize;
    private Camera mainCamera;
    
    // Use this for initialization
    void Start () {
    
        // Initialize variables
        mainCamera = Camera.main;
        orthographicSize = mainCamera.orthographicSize;
    
        // Calculating ortographic width
        float orthoWidth = orthographicSize / screenHeight * screenWidth;
        // Setting aspect ration
        orthoWidth = orthoWidth / (targetAspect / mainCamera.aspect);
        // Setting Size
        Camera.main.orthographicSize = (orthoWidth / Screen.width * Screen.height);
    }
    

提交回复
热议问题