12345678910111213141516171819202122232425262728293031 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameCamera : MonoBehaviour
- {
- float devWidth = 10.8f;
- // Start is called before the first frame update
- void Start()
- {
- float screenHeight = Screen.height;
- // Debug.Log("screenHeight = " + screenHeight);
- float orthographicSize = this.GetComponent<Camera>().orthographicSize;
- float aspectRatio = Screen.width * 1.0f / Screen.height;
- float cameraWidth = orthographicSize * 2 * aspectRatio;
- // Debug.Log("cameraWidth = " + cameraWidth);
- if (cameraWidth < devWidth)
- {
- orthographicSize = devWidth / (2 * aspectRatio);
- // Debug.Log("new orthographicSize = " + orthographicSize);
- this.GetComponent<Camera>().orthographicSize = orthographicSize;
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
|