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.
Making the camera following the player is quite straight forward. Add this script to your main camera. Drag the reference of the player object to the script and then you are done. You can change the values in the Vector 3 depending on how far you want the camera to be from the player.
A single Canvas for all UI elements is sufficient but multiple Canvases in the scene is possible. It is also possible use nested Canvases, where one Canvas is placed as a child of another for optimization purposes. A nested Canvas uses the same Render Mode as its parent.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With