Having text be a child to a game object?
Hello! I need to fix an issue where when the camera moves, all the text on the screen does also. Anyway I can fix this? Thanks!
So I have a camera that rotates around, but when it rotates, the text rotates with it. How would I fix this?
Ins$$anonymous$$d of making the text a child of the Camera, make the text follow the camera with a script that sets its transform.position to that of the camera's.
Example:
void Update()
{
var pos = transform.position;
pos = mainCamera.transform.position;
pos.y = pos.y - 5f;
transform.position = pos;
}
I'm not sure that is right. I want it to be where the text DOESN'T rotate with the camera
This was not an answer. If anything it was its own question. I made it a comment under the main question. Feel free to move it to be under @Lysander's answer, if that was what you meant to do.
So it says it interferes with my $$anonymous$$esh Filter. What should I do?
Answer by Tetopia · Jan 05, 2018 at 01:02 AM
Use a TextMesh instead of a Text component. Put the TextMesh on a GameObject in the scene where it should be, but don't use the Canvas (which is generated automatically when adding Text components).
Explanation: Text components are used for User Interface on the Canvas. The Canvas is just "held in front of the camera" like a head-up-display. TextMesh on the other hand is an actual "in game object" and stays whereever you put it in the world (as long as it is not a child of the Canvas which is as stated above "moved" with the camera.
To whoever wants to add text to seperate object, with many object. This is the best solution for me. You definitely didnt need 100x canvases at all. and can pretty adjust the position easily.
Answer by Lysander · Jan 03, 2018 at 11:46 PM
Depends on the Canvas Render Mode type. If you make the canvas Screen Space - Overlay, then all elements of that canvas will essentially be drawn to the screen. If you use Screen Space - Camera, then it's drawn to the screen of only that specific camera (useful for using different cameras for different 'layers' of UI drawn on top of eachother), and if you use Screen Space - World, then it's drawn in the scene the same way any sprite object would be, and can be behind other non-UI sprites and 3D models, etc....
Technically, the canvasses are automatically placed right in front of cameras at a given distance, not rendered "on" the screen (in the case of Overlay, it's not an accessible scene camera but I think a hidden one just for that purpose), but just keeping the explanation simple here.