Unity手机宽度适配

2020-06-24  本文已影响0人  Albert_d37d

private void MatchScreen()

    {

        float screenHeight = Screen.height;

        float orthographicSize = this.GetComponent<Camera>().orthographicSize;

        float aspectRatio = Screen.width * 1.0f / Screen.height;

        float cameraWidth = orthographicSize * 2 * aspectRatio;

        if (cameraWidth < devWidth)

        {

            orthographicSize = devWidth / (2 * aspectRatio);

            this.GetComponent<Camera>().orthographicSize = orthographicSize;

        }

    }

上一篇 下一篇

猜你喜欢

热点阅读