Unity - different phones sizes - c#

I am using unity for develope to my android phone. I am trying to develope a 2D game. When I put new image(sprite) in my game i can see it fully in unity but when I uploaded the game to my phone, parts of the image are missing from the sides. How can I fit the images sizes on all phones?
I saw the answer for this question but for eclipes java and not unity C#.

In Unity 4.6 version, you can make you UI size adaptive:
Select the canvas where your UI resides
In the inspector, add a component called Canvas Scaler (in 4.6 beta, this is called Reference Resolution component)
Set the reference resolution to the native (or original size) of your sprite/background image
Make sure you choose the right "Screen Match Mode" if the phone's resolution is different.
That is it.
Now no matter how you resize the game view, your sprite can make best fit with it: either fit with the width or height, depending on the phone orientations and aspect ratios. In either case, however, you are guaranteed to see full image, rather than portion of it in your case. See the gif below:

Screen.width and Screen.height are the only unity specific methods you need.
Pass in height, width, and position information to your objects based on your screen size.
The harder part learning the gui.
If you need more help with syntax, take a look at unit's gui documentation and tutorials.

Use Screen.width and Screen.height to get the screen size of current device, then check your target phones screen aspect ratio:
For Window Phone, it's 5:3 and 16:9
iPhone: iPhone 3, 4 is 3:2, iPhone 5, 6, 6+ is 16:9
Android phone has many types.
After you get the that, make sure your sprites are designed in exact ratio for your target phones, and it'll be matched with screen.

Related

Unity Game doesn't fit android screen

I was just testing my android app tonight when I found out that the app doesn't match the phone size.
I made the app specifically for my Android Phone ( SAMSUNG S8 ), with a resolution of 1440 x 2960, and yet when loading the app on the phone, it looks way bigger.
Any fixes to this?
set the Ui Scale Mode as Scale With Screen Size.
also, install the phone Devices simulator package to see the phone preview on Unity, It does not have to export your project just to see the preview
check this out
https://docs.unity3d.com/Packages/com.unity.device-simulator#2.2/manual/index.html
You could try to set the screen ratio. When I had this issue it was due to a ratio issue.
In the Player Settings (Ctrl+Shift+B), set the screen width and Height you needs.
In the Supported Aspect Ratio section, I chose Others.
From the upper-left corner of the game preview window.

Ipad resolution for landscape and portrait - Xamarin ios

I am relatively new to Xamarin ios and am creating an application that
will work in both Landscape and Portrait for both iPhone and iPad.
I have been able to implement both Landscape and portrait on iPhone pretty fine by using a rotation callback method that will invoke a different view with the same layout but adjusted dimensions for the landscape version and on the landscape version I have the same to go back to portrait. This works okay but has some lag at times.
I'm not very sure about what is the right way to present two different UIs for different orientations. If anyone has any suggestions please let me know.
Now I have a list that holds values for Height and Width of the current device and I will devise this by the current device density like so:
maindisplayinfo.height / maindisplayinfo.density
and this gives me the current display dimensions I need. I use this to place my objects relative to a screen portion such as:
CGRect(0, Height * 0.30, Image.Bounds.Width, Image.Bounds.Height)
On rotation on Ipad, the display goes funny even though I have set dimensions correctly and my rotation callback triggers the different views. Not sure what is going on here.
But is there a certain way to do this sort of thing with iPad and iPhone?

How to make Unity Game fit any resolution when resizing the window?

I couldn't find an option to send a picture to better explain what's happening. Here's a Unity Link that has the photos to explain the issue.
I've tried Camera.main.orthographicsize = 4.0f, a solid number to stay on but the Orthographic Size of the camera keeps changing it's size after resizing the window when I'm in free aspect Unity editor mode and even when I export the Unity game with 1920x1080(16:9) resolution. I want it to stay the same size when resizing the window so that the game can always fit inside the screen in any resolution when resizing the window. The default blue background of the camera displays when I stretch the window's width far enough which I don't want to happen.
This Youtube video has the results I'm looking for but the code unfortunately is not working on Unity 2019. The code provided from this video does entirely different things for me and doesn't solve my issue.
From what I understood is that the screen has to has a fixed resolution.
This link will demonstrate the solution. https://docs.unity3d.com/Manual/GameView.html
It does that by changing the
Game View Aspect from free to a fixed resolution.
Unless this is not what you are looking for then I sugest another solution:
Make a black background image that fits the screen size.
Then change the scale of the objects in the scene relative to the camera.
This link will make the scaling solution, Make object visual size constant despite the distance

how to create a responsive scene

I'm currently creating a 2D Android and iOS game using Unity3D engine. I'm testing the game on a nexus 5, and an iPhone 5s device. Everything until now is working fine and I am pretty happy with the result, but when I test that application on an iPad or a Samsung tablet all the objects in my game scene are not in the correct position anymore. Is this a common problem in Unity3D ?
I know I am missing something but I tried to do some research and what I found is only by changing the orthographic camera scale might fix this problem, but I found it as a big amount of code to write as my game have not only one scene but multiple scenes and every scene have it's own game objects.
Is there any other method to do, a good and simple work around for this problem?
It's all about setting the Anchors right.
If you're using the new UI System, make sure you anchor the objects where you want them to be, that's how you will achieve resolution independence.
For more information about anchoring, see this tutorial
Don't have separate scenes for separate devices. You can use the Screen object to check the height and width of your display. Then you can use this to set the orthographic size of your camera to something that makes everything visible as expected.
Update: I misunderstood your question, you say GameObject, i understand UI.
Please check this. I don't have this issue on my game. But when i try it with mac or windows machines, it is problematic. So maybe this can solve.
Other solution is more common which is you and Agumander say, change orthographic size of Camera.
This Is for UI
You can use Unity UI, and don't need to seperate. There are so many different resolution and density devices, you need to create so many scenes. So it is meanless separating scenes.
Unity UI has pixel based solutions which can be very helpfull for many density and resolution options. Forexample, It has VerticalLayoutGroup and HorizontalLayoutGroup for easy list like element visulation.
Most important thing is: Do you want to change UI for different screen size or resolutions? For example iPad has larger screen so user can be see more content. This change UX. Maybe you need to consider this.

How To Apply Bounds in Unity For iOS devices

I've made an unity game for iOS devices. It has a game object(sphere) which moves by the force applied to it. But I want to limit the sphere within the screen bounds.
I've seen the unity reference to Bounds, but i don't know how apply it according to the iOS device screens. Please Help.
ThankYou.
Use Mathf.clamp to keep your movement within the screen size. This will be more efficient than using colliders on the edges of your screen. Just play around with your object until you get the right numbers to keep it on your screen. Of course if you plan to use iOS tablets etc you will need to be able to account for the change in your clamping area.
Here is a link to the Unity Documentation which actually includes an example of what you are trying to do.
http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Clamp.html

Categories