Can I develop for the standard iPhone/Mini/iPad screen sizes at once? Or do I need to make some change and build for each one separately?
Is it just a matter of aspect ratio or is there more I need to know?
Can I develop for the standard iPhone/Mini/iPad screen sizes at once? Or do I need to make some change and build for each one separately?
Is it just a matter of aspect ratio or is there more I need to know?
I think following code snippet work for you. Because it satisfy my needs nicely.
You have to attach this script to your camera object.
public class ControllingCameraAspectScript : MonoBehaviour
{
// Use this for initialization
void Start()
{
// set the desired aspect ratio (the values in this example are
// hard-coded for 16:9, but you could make them into public
// variables instead so you can set them at design time)
float targetaspect = 16.0f / 9.0f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f / scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
camera.rect = rect;
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ImageVideoContactPicker;
public class ControllingCameraAspectScript : MonoBehaviour {
// Use this for initialization
void Start()
{
// set the desired aspect ratio (the values in this example are
// hard-coded for 16:9, but you could make them into public
// variables instead so you can set them at design time)
float targetaspect = 16.0f / 9.0f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f / scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
camera.rect = rect;
}
}
}
Hi.
The best solution for me is to use the theorem of intersecting lines so that there is neither
a cut off on the sides nor a distortion auf the game view.
That means that you have to step back or forward in dependency of the different aspect ratio.
If you like, I have an asset on the unity asset store which automatically
corrects the camera distance so you never have a distortion or a cut off no
matter which handheld device you are using. it is available here:
can someone update the code?
Hello plzzz help me i used this code but it never works on camera
i add this script in my main camera …
Answer me plzzzzz…
@ siddharth3322
is this script need to add only for one camera or every
camera in different scenes ???