Canvas Text not visible - unity3d

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.

Related

Text becomes invisible behind background canvas Unity

I just added 3D Text on my scene and it is invisible on the background of Canvas, that is "Render Mode: Screen Space - Camera". How i can make it visible on background of my canvas?
There are 2 ways to fix this:
Change the Sorting Layer of the obstructing object to be one behind that of the text, or change the Order in layer of the obstructing object to be lower than that of the canvas.
OR
Create a new canvas with a higher Sorting Layer (you may need to create a new one) or Order in Canvas and place the text in the new canvas.
As an example, here I have my normal text in a lower canvas, but I created an overlay canvas for text that absolutely must go above everything else.
I find that the second solution is a better general solution for the issue, as in the first solution you have to change the layers for every object in the scene that might obstruct your text.

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.

While adding a canvas and then text into a gameobject, Canvas and text size problem

I am working on a 2d project with unity engine. (I am a newbie)
As you can see in image I already have a canvas for UI elements but also I have gameobjects under player element. I want to add text inside "govde" element. but when I add it;
at left bottom you can see my game. but canvas and text size is HUGE.
I dont know what is wrong with my game or canvas but I could not solve this.
By the way my gun works well so there are no errors in game. here is a photo of game scene;
Thank you for any kind of help. Have a nice day:)
EDIT : I Wanted to show the text box I wanted; please consider the numbers are so small. What I am asking is when width:2 and height:1 ok my textbox fits inside that car but since it is so small, i cannot show even 1 characters inside text box even if I make font size : 1. My english is not perfect sorry if I make any mistake. Here is picture;
and IF I Make bigger to everything, They don't fit to my game screen. I tried to move camera to far away but that did not changed to my Game Screen.
LASTLY: When I add my a text inside my UI CANVAS, it perfectly fits. But when I add same textbox to game object called Player as I needed, it is TOO BIG
SOLUTION : For anybody who deals with same problem try to create a text object inside a UI CANVAS, after that create another canvas inside game object. And lastly, drag textbox into second canvas . That solved all my problems. My second canvas is still huge and when I make it smaller my textbox gets smaller and smaller so I cannot use it again but I let canvas to be huge, no problem for me at all. Thanks for helps.
The text you created is the tiny black ‘New Text’ above the word basla. The canvas isn't actually viewable, you can add a ‘Panel’ underneath to confirm its size.
edit set font size and change width and height of text
keep scale at 1,1,1, track all the parent scale of each parent object, they do multiply in scale as you go down, so if one parent has scale 2,2,2 and its parent has scale 3,3,3 by the time you get to the text at 1,1,1 its scaled to 6,6,6 so keep this in mind and reorganize you hierarchy as needed

Unity UI elements with different resolution

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.

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?