I’m trying to test dynamic layouts – and while I can configure the camera at start, is there any kind of event I can listen to to detect a change in screen resolution of the game view in the editor so I can modify my layout? Polling the resolution in an update seems like a poor solution.
1 Answer
1I’m a beginner and my solution may not be professional, but try use Screen.width & height:
`
public class MyMonoBehaviour : MonoBehaviour {
public Vector2 LastScreenSize;
protected virtual void OnScreenSizeChange() {
Vector3 v = GetMyCamera().ScreenToWorldPoint(new Vector3( Screen.width-70, 70, GetMyCamera().nearClipPlane));
this.transform.position = v;
}
// Update is called once per frame
protected virtual void Update () {
if ((LastScreenSize.x != Screen.width) | (LastScreenSize.y != Screen.height)) {
OnScreenSizeChange();
LastScreenSize.x = Screen.width;
LastScreenSize.y = Screen.height;
}
}
`