GameCamera.cs 804 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. public class GameCamera : MonoBehaviour
  3. {
  4. float devWidth = 10.8f;
  5. // Start is called before the first frame update
  6. void Start()
  7. {
  8. float screenHeight = Screen.height;
  9. // Debug.Log("screenHeight = " + screenHeight);
  10. float orthographicSize = this.GetComponent<Camera>().orthographicSize;
  11. float aspectRatio = Screen.width * 1.0f / Screen.height;
  12. float cameraWidth = orthographicSize * 2 * aspectRatio;
  13. // Debug.Log("cameraWidth = " + cameraWidth);
  14. if (cameraWidth < devWidth)
  15. {
  16. orthographicSize = devWidth / (2 * aspectRatio);
  17. // Debug.Log("new orthographicSize = " + orthographicSize);
  18. this.GetComponent<Camera>().orthographicSize = orthographicSize;
  19. }
  20. }
  21. }