- Home /
iphone screen size
anyone know how to make a game's screen size fit right for iphone 5 and 6? i wan't it so that when i'm working on unity, it's in the same size as iphone and can detect if it's on iphone's screen.
now i'm using the free aspect ratio. I set the dimensions to 1136 x 640 and i'm working on windows
What type of game? is it 2D or 3D ? are you using the new UI or a third party?
Answer by eelstork · Mar 31, 2015 at 02:44 AM
As to iPhone screen sizes it's all here.
Add a custom screen size to the editor, click the "free aspect" widget and use the + sign at the bottom of the drop down menu.
As to detecting the size of the target device, have you tried? Last time I built a Unity project on an iOS device I seem to recall having done nothing special to get it to work at target device resolution.
Bear in mind that you will need an OS-X computer (aka, a Mac) to create an iPhone/iPad build.
is there a way i can get the build to run at a different aspect ratio when building to pc or web but still detect iphone screen size when building to iphone?
Different iPhone screens have different aspect ratios. So, as to picking the correct aspect ratio for rendering I believe that Unity does this automatically for your main camera. You can easily detect the screen size at runtime, and enforce whatever aspect ratio you like accordingly (even letterboxing etc...). For example see here. (not the only script lying around) As to handling things differently on a platform specific basis you are looking for platform dependent compilation. As another suggested, knowing whether you are creating a 2D or 3D game (or dealing with these related to the UI or scene...) will help us understand what you're getting at.
Please try to improve your question. $$anonymous$$aybe your question should be "How to manage aspect ratio across devices?" ins$$anonymous$$d of iPhone screen size, which isn't really a question, and will be overlooked as potentially not related to Unity 3D. It is poor form to ask additional questions in comments. If the added question doesn't stand in its own right, consider updating the original question.
Answer by alok-kr-029 · Mar 31, 2015 at 06:27 AM
I set the screen size to one aspect ratio and update as so it work perfect for me for any screeen size
void Start ()
{
if( this.GetComponent<Camera>().aspect > 0.7f && this.GetComponent<Camera>().aspect < .8f)
{
//print ( this.GetComponent<Camera>().aspect );
GetComponent<Camera>().orthographicSize = 6.46f;
}
else if(this.GetComponent<Camera>().aspect > 0.52f && this.GetComponent<Camera>().aspect < .58f)
{
//print ( this.GetComponent<Camera>().aspect );
GetComponent<Camera>().orthographicSize = 8.38f;
}
else if(this.GetComponent<Camera>().aspect > 0.6f && this.GetComponent<Camera>().aspect < .67f)
{
//print ( this.GetComponent<Camera>().aspect );
GetComponent<Camera>().orthographicSize = 7.18f;
}
else if(this.GetComponent<Camera>().aspect > 0.55f && this.GetComponent<Camera>().aspect < .59f)
{
//print ( this.GetComponent<Camera>().aspect );
GetComponent<Camera>().orthographicSize = 8.21f;
}
}
You may already know this but ins$$anonymous$$d of making up to 8 calls to
this.GetComponent()<Camera>.aspect
you could set a couple of variables at the start for more efficient and easier to read code.
var cameraComponent = this.GetComponent<Camera>();
var cameraAspect = cameraComponent.aspect;
if (cameraAspect > 0.7f && cameraAspect < 0.8f)
{
cameraComponent.orthographicSize = 6.46f;
}
...
Your answer
Follow this Question
Related Questions
Unity 3.5 allows terrains on iPad2 and newer iOS devices, what's the max terrain size? 0 Answers
Splash screen orientation - iOS 2 Answers
How to have my mobile device screen lighting on all the time 2 Answers
Using dual touchpad prefab 0 Answers
What is causing a single hiccup at start of IOS game? 1 Answer