Download presentation
Presentation is loading. Please wait.
1
Cameras in Unity What are you looking at?
Programming – Cross Platform Development
2
Contents Camera options in unity Camera.main
Perspective vs Orthographic Skyboxes Culling Renderpath Camera.main Changing the current camera Post effects Using multiple cameras Rendering layers
3
Cameras in Unity Cameras are the viewports through which we see the scene. There are many things you can do with cameras to add interesting effects to your games When you create a new scene, the main camera is one of only two GameObjects created for you
4
Camera Options in Unity
There are some simple options you can set on a camera. You can: Switch between perspective and orthographic projection Change the field of view or size of the view frustum Change the rendering path between deferred and forward
5
Perspective and Orthographic
The simple way to think about these is that perspective is for 3D and orthographic is for 2D
6
Rendering Paths Rendering paths are different methods unity uses to light the objects in a scene Deferred The more advanced form of lighting. Allows for many more active lights in a scene, however this is not supported on some older hardware Forward The more traditional lighting method. Doesn’t support as many high detail lights, but runs on legacy hardware
7
Switching cameras Camera.main is a static variable you can access from any script that stores a reference to the current camera. If you only have one camera active in the scene, that camera will be the main camera To switch what the currently active camera is, we simply turn off the current camera and switch on the new camera we want to use.
8
Active and Inactive GameObjects
activeInHeirarchy All GameObjects can be turned on and off. You can change this in code using the activeInHeirarchy variable in the GameObject class this.gameObject.activeInHeirarchy = false; We can also turn on and off individual components inside of a GameObject This can be set in code by changing the enabled member variable of this.enabled = false; In the editor, these are handled by the tick boxes next to each component enabled
9
Active and Inactive GameObjects
Turning components off means that their update functions will no longer be called Turning GameObjects off disables all of their child components. You can easily change what the current main camera is by having multiple cameras in the scene, with only one enabled at any time.
10
Rendering layers Cameras have the ability to cull GameObjects based on a set of matching flags All GameObjects can have a Layer (We’ve seen this used for the collision system already) Cameras can be set to only render GameObjects in certain layers You can modify what layers a camera renders by using the Culling Mask option in the inspector.
11
Using Multiple Cameras
You can have multiple cameras enabled in a scene at the same time. This can be used to create a variety of effects, especially when combined with layers Simple Geometry for a skybox environment Parallax effects in a 2D game Rendering a minimap Split screen multiplayer All cameras have a depth value. This is used to decide what order the cameras are rendered in. Cameras with lower depths are rendered before cameras with higher depths
12
Clear Flags If you just put multiple default cameras in the scene, each will write over all of the previous ones and only the one with the highest depth will ever be visible. This is because of clear flags By default, each camera clears all the work the previous cameras did. You can change the clear flags for a camera using the inspector.
13
Post Effects You can add post processing effects such as depth of field, antialiasing, bloom, motion blur, and many more. We won’t discuss implementing your own, as that is a second year topic, however you can use many of the premade ones by importing the Effects standard asset pack and adding the provided components to a camera
14
Summary Cameras are where scenes are rendered from
You can change many of the properties of cameras using the inspector or from code Cameras can be switched by simple enabling and disabling them Cameras can selectively cull GameObjects based on Layers Multiple cameras can be used in the scene at once, but must have their clear flags set correctly
15
References Unity Technologies Unity - Manual: Camera. [ONLINE] Available at: [Accessed 09 February 2016].
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.