- Home /
Question by
DarkMarmot · Nov 15, 2013 at 10:39 PM ·
screenresize
Testing orthographic camera at various resolutions -- detect window resize?
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.
Comment
Answer by zemanpg · Nov 25, 2013 at 12:02 AM
I'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;
}
}
Your answer
Follow this Question
Related Questions
Fix Resizing For GUI Label? 1 Answer
Resize NGUI at Run Time 1 Answer
Anchor The Objects. 1 Answer
Automatic Screen Resize 4 Answers
Resolution Dialog missing for Linux? 1 Answer