Auto resizing in 2d game

HI everybody,
I am creating a 2d game for Android but I have a problem. putting the game on different devices with different resolutions, the view of the game changes (of course) from device to device. is there a way to make an “universal” mobile game?
thanks to all for the answers.

I’m new in Unity and while I was learning tutorials I didn’t see any problems with resolutions… but seems I was wrong and there are a problem, if the aspect ratio changes (not resolution), the game will have some black parts.

I will tell to you my personal opinion, this is not tested, and most probably there are some better solution… You could solve this problem by making different scenes which has different aspect ratios. And on start of your game calculate what is the current aspect ratio, and go with that scenes… So, in this case you will not have any problems with different screen devices…

Maybe someone have other options, but so far it looks simple and best for me. Hope it helps.

Attach this script to your camera and adjust the property ‘Reference Screen Height’ in the Inspector until you’re happy. At least, this might lead you into the right direction.

using UnityEngine;

[RequireComponent( typeof( Camera ) )]
public class CameraSetup : MonoBehaviour
{
    public float m_referenceScreenHeight = 768;
    public float m_pixelsPerUnit         = 100;

    void Awake()
    {
        float ratio = Screen.height / m_referenceScreenHeight;
        this.camera.orthographicSize = Screen.height / 2 / m_pixelsPerUnit / ratio;
    }
}

Thanks to both. In particular the script of Bivrost works very well. Then problem solved. Thank you all.

I didn’t get that script… What it does, it just changes the ortographic size of camera… What if it goes beyond my sceen? Say my ortographic size is 3.2 and it will make it 3.5… then I will have a black screen… I’ve tested it, and it doesn’t work.