Unity UI elements with different resolution - unity3d

I have added an image as a canvas child, the image is just a layout to outfit UI text elements like in below image.
here the black outline is the image and red one is their bounds which we can see in editor, the blue text is UI Text element with anchor preset bottom stretch and right = 100. The canvas render mode is screen overlay, scale with screen size, reference resolution is 1920x1080. Thus in image 1, the UI text is in middle, but in image 2 (different resolution) it does't look like in middle.

You need to set Text anchor preset to bottom-center to achieve that Text is always in the middle-bottom of the screen.
This manual is a great Instruction of how you can position UI elements relative to the Canvas and each other.

Related

How make the textmeshpro text to be in front of rawimage or just image?

i don't want to make the image transparent but to make the text to be on the image.
now the black image is blocking the text.
The canvas is set to screen space overlay.
(Assuming the text colour is different from the image colour as #alfix suggested) if changing the Z position of the canvas elements doesn't change their render order, reordering them in the hierarchy should. Objects lower in the hierarchy should render on top of items prior to them in the hierarchy.

Setting X of camera's viewport causes the black strip to be rendered

I’ve run out of ideas, please help me.
That's the situation:
Imagine a simple object in the center of screen (it's always so, because camera has an orbit script)
Then we add a canvas image, 300px width, for example, on the right side of the screen (blue one in the picture). Our cube is not centered anymore.
For example, we can change X property of camera viewport rect, but we'll get a black strip and if object appears in this zone, it would not be rendered.
So, what can I do to offset camera position?
Thank you in advance!
The best option I have for now is:
create basic UI for FullHD resolution and make right panel as wide as black strip is
if user's screen bigger than 1920px, than change Canvas Scaler mode from Constant pixel size to Scale with screen size

How to change canvas' size in unity3d

I can not change canvas' size when it's in Screen Space - Overlay Mode; After some research I found that the size of a canvas is determined by your game's screen size. The canvas just covers your screen. So I think I could change my camera's size to change canvas' size. But it does not work. Does anyone know how to set a specific size to a canvas?
So may be my question should be how to change the screen size showed
in editor?
To change the screen size, go to the Game window (accessed by the menu "Window->General->Game"). At the top of the window will be a screen size menu (outlined in green, below) to change the screen size. When pressed, it will display the list of screen sizes that will be emulated. I say "emulated" instead of "displayed" because it is possible to have a screen size larger than the screen on which you are working. It is also possible to zoom into a screen. The "Scale" slider (to the right of the screen size menu) will allow you to scale up/down.
As a note, the list of screens and resolutions shown are related to the current build target (accessed by "File->Build Settings..."). For example, common iOS screen sizes are displayed in the list when the build target is iOS.
Use the Canvas Scaler Component
Unity3D Documentation: Canvas Scaler

Unity - Keeping UI centered no matter the screen resolution

I want to keep my UI looking the same no matter which resolution the screen is at I am running of 16:10 in my game view and I want the UI to stay the exactly the same and centered even if the screen resolution changes.
Screenshot of UI
For the UI in the screenshot, I assume you want it always at the bottom of the screen and always the width of the screen.
For always taking up the width of the screen, select your canvas and go to its canvas scalar component. 'Change UI Scale Mode' to 'Scale with Screen Size' and adjust Reference Resolution to a resolution that looks good for you. Then the canvas elements will be the same width on all resolutions.
For always staying centered at the bottom of the screen, select the UI elements themselves, or their parent if they have one. Change their anchor to bottom center.
For more information about how to design for all screen resolutions, check the documentation as Hellium suggested!

Canvas Text not visible

I have a rectangle that I want to display score on. I want the text to be on this game object, so I set the canvas to World Space and not Screen Space (Overlay) which is the default. I change the size of the canvas & text and place them a bit in front of the rectangle.
Here you can see the text object in front of the rectangle:
Here is the game view - there should be some text visible here but there isn't:
Here is the hierarchy - the grey rectangle is the outermost object. When I added a text component as a child it got its Transform changed to a RectTransform.
Set the canvas size big like 800x600 and then scale it down to 0.001 or so, then set the font size accordingly. :)
World space canvas are capricious.
Your canvas is attach to your camera?
In all case if it's just to display only a text some where in world space like your score, take a look to TextMesh that is at "3D" text, you can attach where you want in your world.
Hope this helps.