Image Stretch in Unity when using for Sniper Zoom - unity3d

I am trying to making a sniper zoom using unity. When user zooms i want to show
Sniper Scope image.
I simple place the image in Unity Image Component.
Here is the image example
The image stretches like this.
How can i maintain the aspect ratio. There is once option for saving the aspect ratio but then it removes background from top and bottom

Related

How do I make Pixel Perfect Camera scale like Normal Camera in Unity 2D

This is my scene
Right now if I use resolutions that aren't 16:9 the Pixel Perfect Camera zooms out quite a lot showing parts that shouldn't be shown.
How do I get it to scale like the Normal Camera which just cuts out parts outside the borders?
The Reference Resolution is currently set to 320x180, I tried changing the Reference Resolution to other resolutions (640x360, etc) but that changed nothing.
Tried Pixel Snapping on/off.
Cropping the X and Y does a good job at hiding the outside borders places but makes the screen too small for non 16:9 resolutions.

How to keep the same resolution of canvas on different screen resolution?

First of all, sry for my English mistakes, I'm not a native English speaker.
I'm trying to make an UI which is composed of a canvas within different gameObject, and I would like that my canvas scales to the dimension of the screen but keeps its original resolution (16x9 portrait). If it is displayed on a tablet resolution (4x3) then an image is displayed in the space that is not covered by the canvas.
But actually all I've got is a canvas which scales to every resolution, and it changes the aspect of its child (for example a square becomes a rectangle).
Thank you for showing interest in my query!
UI's are heavy beasts. Canvas in Unity have a component attached to themm called Canvas Scaler which is set by default on Constant Pixel Size. You may try to set this property on Scale With Screen Size and then specify the base resolution you want to work with (usually 1920x1080 is a console standart). This is your first step
Then, to avoid strange Image scaling, you may check the property Preserve Aspect, this way the ration of the Sprite into your Image will remain the same indepently of the ratio of the Image
Last, you may play a bit with anchors but this is another story, you should let those at plain center at the beginning and come back to it when you will feel ready
Hope that helped ;)
Your canvas should have a component called Canvas Scaler. Here it should say Constant Pixel Size, change this to Scale With Screen Size and it should lock the Canvas to be the same width / height as the screen. If you want to lock an image to a specific width/height ratio, go to the Image component on the image and check the Preserve Aspect checkbox. This way if you have a 100x100 image, the images width will always be the same as the height. If you have a 200x100 image, the images width will always be twice the height, etc etc etc.

Canvas too big for the camera in Unity

I have created a 2D game with an orthogonal camera and using 16:9 display size.
I dragged my background image onto the hierarchy (it's about 2048x1152) and then set the camera size to be 22.5, which made it fit the background perfectly and displays just right.
However, when I add a Canvas for a UI it is absolutely giant, about 100 times bigger. It only becomes 'normal' size with respect everything else added when I set the camera to its default size of 5. So when I add a small graphic, it too becomes giant.
I'm simply following a book I read and I'm not doing anything to deviate.
Am I doing something wrong? Below is what I mean. The background image is the little image in the bottom right and the outlined rectangle is the canvas with a small graphic added.
Thanks.
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render Mode to Screen Space - Camera.
Make sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
You should use the Unity canvas for this along with the canvas scaler component. If I'm not mistaken it will scale all elements relative to the screen they are viewed on.
The canvas scaler allows you to match the scaling based on a preferred viewport size which is a life saver.
However this may not fit you needs perfectly as it would mean that the background element would become fixed. So if you wanted to pan the element you would need to move it's x and y elements within the canvas.
Hope that helps?

Unity3d background

I'm trying to get an image to be a background on my camera. It's one picture, it doesn't need to be repeated. It would be nice to have it stretch out when the resolution of the screen changes. I've found older tutorials that show how todo it in an older version of unity, like this one: Link
However it seems that functionality is no longer in the newest version of Unity. Does anyone have any idea how to put a single picture as background?
thanks in advance.
Add a Canvas (UI --> Canvas) to your scene and set it's render mode to "Screen Space - Camera".
Set the Canvas' Render Camera to your scenes main camera (i.e. the camera you render your 3D scene with... or the only camera in the scene ;) )
make sure the Plane Distance of the Canvas is set to the far plane of your camera. So if your far clipping plane is set to 1000 set the Plane Distance to 1000 as well (or 999, if images in the canvas happen to be clipped away by the camera). If your Plane Distance is lower than the far clipping plane of your camera, objects behind the Plane Distance will be occluded by Images on the canvas.
Add an Image (UI --> Image) to the Canvas and set its anchor presets to strech on both axes.
Set the Left, Top, Right and Bottom Parameters of the Image's Rect Transform to 0. Now the image should be full screen and adjust to any change in the aspect ratio.
That should do the trick :)

Image size incorrect in Unity

I have a Unity 2D project with a fixed screen size of 800x450 pixels.
I have imported a background image that is also 800x450 pixels.
When placed on the stage, the image only takes up half of the screen.
The scale of the image is set to 1,1. The Z position is 0.
Why is the image displayed too small? How can I display the image at the correct resolution?
Does this mean that I have to design all my game assets at 2x the required size? Or that I somehow have to set the scale for all imported assets at 2? What is the recommended workflow?
EDIT
I have added a screenshot of the camera settings:
I would trying making your camera orthographic, and set the size of the camera (not the transform) to be half the height that you would like it to be (225)
Also if you are looking for pixel perfect game. here is a pretty good article from Unity about how to make that work and it explains some of the camera aspect ratios and scaling
http://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/