GameCamera.cs 942 B

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