Is there a way to get the game view window size in code?
I have looked through the documentation for UnityEditor, GetWindow, and exhausted everything I can think of through the arduous try-everything-in-intellisense discovery method, with no results yet.
When I check Screen.width the width of the current inspector window comes out, not the actual width of the game view.
When I use Screen.currentResolution.width, I get the target build resolution, not the current view size.
Is this possible?
Thanks in advance
Answer by zombience
Oct 21, 2013 at 11:14 PM
Ah. Just discovered it after far too long looking for this:
string res = UnityStats.screenRes.Split('x');
Debug.Log(int.Parse(res) + " " + int.Parse(res));
Thats it. it'll do the trick.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
15 People are following this question.
Change position using custom and native editor
Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene
Some public attributes not shown in inspector, default references
Distribute terrain in zones
Custom objects from editor scripts?