I am making a Unity2D card game. But It cannot fit to all different mobile devices screen size. Is anyone can give me some hits, how to fix the problem?
This is a common problem and there’s a lot of way to solve this problem , so i’m just going to tell how i overcome it , it might be different from other people .
- First , set your game screen resolution to the resolution size that you use to develop the game
- Then add a canvas gameobject from GameObject>UI>Canvas
- Change the Render Mode in Canvas component to Screen Space - Overlay
- Change the UI Scale Mode in Canvas Scaler component to Scale With Screen Size
- Input the reference resolution , it’s the resolution size that you use to develop the game
- Change Screen Match Mode into expand
- Create empty game object as the child of the canvas
- Add RectTransform component and Canvas Renderer component to the empty game object
- Set the anchor preset of the RectTransform to “stretch to all side” , it’s probably at the right bottom corner of the menu
- Move all your game object except for camera as a child of the empty game object
Now change the screen resolution in the game screen , it should resize accordingly
I don’t know if you’re having the same issue as me, but everything was working fine in the editor other than when I switched to a different screen size. I had nested canvases which were inheriting the scale and they were not properly scaling until I manually switched them off and on and I guess this just forced them to re-calculate the scale relative to the parent canvas. Anyhow, I got rid of the child canvases as I realized that I have no other use for them other than to organize my panels at this point and it went away… This definitely seems like a bug to me, but you’re not mentioning canvases at all, so maybe your issue is not directly related. Hopefully it helps someone though