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

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

Related

Smaller Screen when Build and Run to Android

I am very new to unity and I'm making my first game, Snake. However, when I build and run it for android everything is very small and is hard to press. Scaling everything up works however when I press play everything is huge and some are out of the screen. Does anyone know why this is happening?
Thanks
Go to your UI canvas and to the canvas scaler, set it to "scale to screen size" and change the resolution to your prefered resolution.
canvas scaler

How to set portrait aspect ratio for Windows build in Unity

I'm trying to build a unity project for standalone and the game is in portrait configuration. Everything works fine when I test it in the editor, but when I build it, everything UI related is messed up and by that I mean it tries to fit to the screen's aspect ratio causing many buttons and UI elements to be off-screen despite even manually trying to change the screen size by doing Screen.SetResolution(1080, 1920, false); and stopping the game from entering full-screen mode in the build settings so that it would become a portrait aspect ratio but nothing is working. The game itself is working fine which is not a part of UI or any canvas obviously. Any help would be much appreciated!
UI scaling is tricky particularly is you have different aspect ratios, and also if you have different resolutions (although they are different). The most important things from my experience are making sure you've anchored things as reasonably as you can, used layout groups for dynamic content (dropdowns, instantiated elements, etc.) and used the CanvasScaler component on your canvas.
The Canvas Scaler component can be found on your canvas object in the scene, and is the first place to start when dealing with variable screen sizes. . This mode is the best for variable screen sizes, you can set this up to be your preferred screen size and then make your UI fit that size, then automatically scale based on your ideal size.
It's hard to say what is the best way to anchor your UI elements generally speaking, but if you don't want them centred on the middle of the screen it likely isn't the default. I often find anchoring the sides of an area, or corners, is best.
Finally, depending on your platform and handled screen orientations, you can also set device orientation preferences in Player Preferences. . Exactly what you set may depend on your project, but can be an important step in making sure your UI scales correctly for you targets.

Blurring a texture taking too much time in unity 2d

I'm making a 2d game for android where I want to make the background blur when a popup opens.
I have tried so many techniques.
Making two camera. Blurred main camera and changing culling mask of secondary camera to the popup layer.
Using grabpass shader in a material and adding it to the background of popup.
Capturing screenshot, blurring the texture and adding it to background of popup as sprite.
Everything doing exact what I want to do. But either they are eating FPS or taking a huge time at first time.
So is there any way or workaround which will not slow it down or lag?

XNA Viewport confusion

I want the game to adapt to the screen resolution, but I want the viewport to always stay the same, so the game basically just resizes itself when running on different PCs. How do I do it?
So, for example, screen resolution is 1920x1080 and the viewport is 640x480. How do I stretch those 640x480 onto 1920x1080? Is that even possible?
If this did not make any sense, I'll try to explain another way.
Thanks in advance!

c# how to perform a screen clipping similar to OneNote Windows + S shortcut key

I'd like to implement a similar screen clipping functionality to that of OneNote. Basically it can draw a translucent overlay on top of the whole screen, and also freeze the screen so users can clip a portion of it.
I've done some research around and it seems that the easiest way is to create a translucent TopMost form with the size of the whole screen and then perform clipping on this form. This approach, however, is slow. I see some other suggestions about doing a Direct3D hook for drawing overlay, but this is probably too complicated and I'm not sure how stable it is with respect to different Direct3D version. Any ideas how OneNote does it?
I think instead of creating the transparent layer on top of the screen, just grab a screenshot of the whole screen and make it full screen. So users are drawing on a static image not a translucent layer. Since it is a screenshot already, it is already frozen. I think this is how they do it anyway, I doubt an application can simply freeze a screen, they take a photo of it and cover your screen with it, so its as if its frozen.

Categories