Public Group

# Android programming on Unity3d

This topic is 1019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i've been working, studying and practicing game programming for some time now, but i am stuck with this problem for a while and i can't seem to find any sources across to web to resolve this issue, hopefully someone will come up and at the very least point me at the right direction; i've noticed when i build my game for android, the resolution does not scale properly, not just that but since there happens to be dozens of different phones with different resolutions i can't really go around it, just by making it fit according to a single resolution.

What i'm really looking for is basically a beginners guide to android development in unity3d, but some answers on my problem or reminders on what to do and what not to do regarding the topic is also appriciated.

##### Share on other sites

I'm sorry to disappoint you but you wont find a straight forward solution to your problem as there aren't a feature in android that does what you require it to do. Instead I can tell you what I did to tackle this problem on my own when I developed two games exclusively for the android platform.

First thing you must do is sit down and write down what mobile resolutions do you want to support mostly? People today use a variety of smart phones which in their case use a variety of resolutions that you just cant track individually. However what you can do is look for the phone with the highest resolution up to this day which is probably 1440 x 2560 for Samsung S6. After doing that you're gonna have to make all the assets for your game to be aesthetically pleasing accordingly.

Now you have a game that probably has the highest resolution for smart phones at your hands, but what about those who have almost the same, mid and low resolutions? You scale the assets down. How?

You can do it by getting the X (getX();) and  (getY();) methods in the android IDE.

Lets say someone has a very old smart phone with the resolution of 800 x 500

double width = getX();

double height = getY();

if (height <= 800 && width <= 500){

*Display the assets in a matter that would fit the screen*

}

The only downside to this will be rapid testing for many resolutions, but since you're using unity3d I don't think that would be a problem at all.

This is the fastest and easiest solution I came up with as a beginner game developer so it is definitely not the best.

##### Share on other sites

Thanks for your response but my main problem is the GUI elements that are displayed through code, to get into more detail, will not respond the same way, and i'll have to modify everything through code (select the length, width, coordinates with respect to screen size - screen.width / screen.height), which does not really leave me with much flexibility, as i can only manage certain effects and properties through coding-displaying functionality of Unity3d. Which leads me to believe there must be a way to scale those up properly, i can't publish separate versions for every resolution, it's impractical and kind of repulsive for users, in my opinion.

##### Share on other sites

You can simply move each object of your GUI based on the ratio :

using UnityEngine;
using System.Collections;

public class UpdatePosWithRatio : MonoBehaviour
{
void Start()
{
float Ratio = (float)Screen.width / (float)Screen.height;
float Factor = Ratio / (16.0f / 9.0f);
transform.position = new Vector3(transform.position.x * Factor, transform.position.y, transform.position.z);
}
}

1) You place all your GUI object using 19/9 ratio as preview.

2) You add this script on each GUI object, on the start it will move each object based on the actual ratio.

Edited by Alundra

##### Share on other sites

I appriciate the answers, but that leaves me with the problem of fonts; i currently use skins to manage fonts along with the borders and styles. If i choose a big font it will work on big screens but won't work with the smaller ones; do i have to publish more than a single .apk?

##### Share on other sites

I hope I'm understanding your problem correctly. First of all, I assume you are using version 4.6 or newer of Unity and that you are using it's new UI system.

Have you set the properties of the canvas scaler properly? On the UI canvas there is a canvas scaler component attached that allows you to make the UI elements scale for every resolution (under 'Ui Scale Mode'). This scales all the items including fonts along with the resolution and should be what you need. There's some information on the Unity webpage here

There is also information on how you can use anchors to both make these items scale as you like and to keep their relative positions over here.

Next to that, Unity also offers a set of video tutorials on their (new) UI. I personally quite liked them and it might be a good start (assuming you don't know about the discussed topics yet).

If you all set this up correctly, there shouldn't be much of a need for finding Android guides specifically as Unity automates most of this process for you. An issue you might encounter is different aspect ratios (they scale properly to the same aspect ratio, but might not always work out as expected once this differs). You can play a bit around with the settings on the canvas scaler and with the anchors to help this.

Hope this helps!

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
17
5. 5

• 9
• 14
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
631756
• Total Posts
3002113
×