K
K
Keliorw2020-09-24 22:05:36
Unity
Keliorw, 2020-09-24 22:05:36

How to make the game responsive?

I was writing a game and faced such a problem that when you start the game on your phone, the game does not adjust to the resolution of the device, and I did not find a single normal answer or guide on the Internet and forums, everything I found works with errors, well, or some then crutch methods.

Here seems to be one of the working methods, but I do not quite understand how to fix the error. If anything, it should be so, so that only permission is output to the console.

void Awake()
    {
        foreach (var res in Screen.resolutions)
        {
            Debug.Log(res.width + "x" + res.height + " : " + res.refreshRate);
        }
    }


It gives the following error:


UnityException: get_resolutions is not allowed to be called from a MonoBehavior constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'Controller' on game object 'Controller'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEngine.ScreenShimBase.get_resolutions() (at :0)
UnityEngine.Screen.get_resolutions() (at :0)
Controller..ctor() (at Assets/scripts/Controller.cs:12)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2020-09-25
@Keliorw

In canvas choose Scale With Screen size https://docs.unity3d.com/Packages/[email protected]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question