Created
March 22, 2018 14:40
-
-
Save drcharris/fef50007791ed9d3a24a4cfe302df46d to your computer and use it in GitHub Desktop.
Adjust Cinemachine camera so that your screen width always matches a specific Unity units width.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Cinemachine; | |
using UnityEngine; | |
/** | |
* Force the Cinemachine camera to make viewport exactly as wide as the bounding object. | |
* This allows us to always be 100% wide regardless of device. Handy for vertical scrollers. | |
*/ | |
public class FWCam : MonoBehaviour { | |
public int fullWidthUnits = 14; | |
void Start () { | |
// Force fixed width | |
float ratio = (float)Screen.height / (float)Screen.width; | |
GetComponent<CinemachineVirtualCamera>().m_Lens.OrthographicSize = (float)fullWidthUnits * ratio / 2.0f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great, thank you.