How to add a Camera to a GameObject

Viewed 154

I am new to Unity and am working on a UI project. I want to add a Camera targeted on a GameObject in the Canvas. There is a Camera with the same hierarchy of the Canvas and when I clicked it the preview is blank but when I play the project everything is shown, including all the buttons texts images.

How does the Camera work with UI and is it possible to add a camera targeted on a GameObject?

1 Answers

For your main Canvas, you do not need a Camera. Please see the Unity Manual for information regarding the Canvas. Take note of the Render Mode option on the Canvas Component. If this is set to Screen Space - Overlay then you will not need a camera to view UI Items or GameObjects that are placed as children to this GameObject. It will also inherently not appear in your Camera Preview if it is located under a Canvas of this type.

If you would like to have other GameObjects show up in the Camera Preview, add them to your scene and ensure that they are not under the Canvas GameObject. Then ensure that they are in range of your Camera.

Hope this helps!

Related