Match Canvas with Main Camera - Unity - unity3d

I want to use the Canvas and UI Text to constantly show the score of my game on the top right corner of the screen. How can I initialize the Canvas so that its position and dimensions perfectly match the border of the camera? (2D Setup)

To see the canvas fit into the camera's size in the scene, change the Canvas component's Render Mode to Screen Space - Camera, and drag the camera from the hierarchy to it.

Related

Why the cube is transparent on the canvas/panel ui?

I want to animate the cube over the ui panel.
The Canvas is set to Render Mode : Screen Space - Overlay
The Panel have my own source image
The Camera Clear Flags set to Skbox and Culling Mask to UI only
The Cube layer is set to UI
But the Cube is transparent and I want it to be full like a regular Cube.
I think #Draco18s is right, for you to render UI behind stuff you need to change the Canvas to Camera or World space and then configure Z position in transform of the background (or depth in canvas component) to make it stay behind your cube.
Remember to add a camera to the canvas.

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 :)

Unity Canvas does not fill screen

I have a 2D game set to 1080p pixel size (so each unit equals 1 pixel) and I have added a canvas to my scene. However the canvas fills only about 1/8th of the screen and is also not central either. All the canvas size and position settings are locked so I cant move it or resize it. The canvas itself does reflect the screen (ie if I put text in the top right corner it appears correctly) but the size makes it hard to judge where best to position the elements).
How do I get the canvas to fill my scene?
On your canvas, set the Canvas Scaler component's Ui Scale Mode to Scale with Screen Size. Then you can define a Reference Resolution of 1080p, i.e. 1920 x 1080.
EDIT: To see the canvas fit into the camera's size in the scene, change the Canvas component's Render Mode to Screen Space - Camera, and drag the camera from the hierarchy to it.
(check this video)

How to change canvas position in Unity?

I'm very new in Unity and in GameDevelopment at all. So I've started with Roll-a-Ball tutorial. And now I have a trouble with UI Lesson. When I create Text element Canvas parent creates in strange position.
But in lesson I see that Canvas is near Player object. How can I move it?
If you want to see the canvas fit inside your scene camera's view, change the Canvas's Render Mode to Screen Space - Camera; then drag the Main Camera onto the newly visible Render Camera field in the inspector.
See the bit in your canvas inspector about it being "screen space - overlay"?
That means:
"This render mode places UI elements on the screen rendered on top of the scene. "
And what THAT means, is that you don't have to worry about where the Canvas and child Text show up in your scene view. When you run the game the UI elements will overlay on the background world objects and it'll all be fine.
Source:
http://docs.unity3d.com/Manual/UICanvas.html
It shouldn't matter where the canvas is located, but you can select the child object called 'text' and change the X and Y values to move it around the screen. I hope this helps!