Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Camera

class in UnityEngine

/

Inherits from:Behaviour

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

A Camera is a device through which the player views the world.

A screen space point is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth,pixelHeight). The z position is in world units from the Camera.

A viewport space point is normalized and relative to the Camera. The bottom-left of the Camera is (0,0); the top-right is (1,1). The z position is in world units from the Camera.

A world space point is defined in global coordinates (for example, Transform.position).

See Also: camera component.

Static Variables

allCamerasReturns all enabled cameras in the scene.
allCamerasCountThe number of cameras in the current scene.
currentThe camera we are currently rendering with, for low-level render control only (Read Only).
mainThe first enabled camera tagged "MainCamera" (Read Only).
onPostRenderEvent that is fired after any camera finishes rendering.
onPreCullEvent that is fired before any camera starts culling.
onPreRenderEvent that is fired before any camera starts rendering.

Variables

actualRenderingPathThe rendering path that is currently being used (Read Only).
aspectThe aspect ratio (width divided by height).
backgroundColorThe color with which the screen will be cleared.
cameraToWorldMatrixMatrix that transforms from camera space to world space (Read Only).
cameraTypeIdentifies what kind of camera this is.
clearFlagsHow the camera clears the background.
clearStencilAfterLightingPassShould the camera clear the stencil buffer after the deferred light pass?
commandBufferCountNumber of command buffers set up on this camera (Read Only).
cullingMaskThis is used to render parts of the scene selectively.
cullingMatrixSets a custom matrix for the camera to use for all culling queries.
depthCamera's depth in the camera rendering order.
depthTextureModeHow and if camera generates a depth texture.
eventMaskMask to select which layers can trigger events on the camera.
farClipPlaneThe far clipping plane distance.
fieldOfViewThe field of view of the camera in degrees.
hdrHigh dynamic range rendering.
layerCullDistancesPer-layer culling distances.
layerCullSphericalHow to perform per-layer culling for a Camera.
nearClipPlaneThe near clipping plane distance.
nonJitteredProjectionMatrixGet or set the raw projection matrix with no camera offset (no jittering).
opaqueSortModeOpaque object sorting mode.
orthographicIs the camera orthographic (true) or perspective (false)?
orthographicSizeCamera's half-size when in orthographic mode.
pixelHeightHow tall is the camera in pixels (Read Only).
pixelRectWhere on the screen is the camera rendered in pixel coordinates.
pixelWidthHow wide is the camera in pixels (Read Only).
projectionMatrixSet a custom projection matrix.
rectWhere on the screen is the camera rendered in normalized coordinates.
renderingPathThe rendering path that should be used, if possible.
stereoActiveEyeReturns the eye that is currently rendering. If called when stereo is not enabled it will return Camera.MonoOrStereoscopicEye.Mono. If called during a camera rendering callback such as OnRenderImage it will return the currently rendering eye. If called outside of a rendering callback and stereo is enabled, it will return the default eye which is Camera.MonoOrStereoscopicEye.Left.
stereoConvergenceDistance to a point where virtual eyes converge.
stereoEnabledStereoscopic rendering.
stereoMirrorModeRender only once and use resulting image for both eyes.
stereoSeparationDistance between the virtual eyes.
stereoTargetEyeDefines which eye of a VR display the Camera renders into.
targetDisplaySet the target display for this Camera.
targetTextureDestination render texture.
transparencySortModeTransparent object sorting mode.
useJitteredProjectionMatrixForTransparentRenderingShould the jittered matrix be used for transparency rendering?
useOcclusionCullingWhether or not the Camera will use occlusion culling during rendering.
velocityGet the world-space speed of the camera (Read Only).
worldToCameraMatrixMatrix that transforms from world to camera space.

Public Functions

AddCommandBufferAdd a command buffer to be executed at a specified place.
CalculateFrustumCornersGiven viewport coordinates, calculates the view space vectors pointing to the four frustum corners at the specified camera depth.
CalculateObliqueMatrixCalculates and returns oblique near-plane projection matrix.
CopyFromMakes this camera's settings match other camera.
GetCommandBuffersGet command buffers to be executed at a specified place.
GetStereoProjectionMatrixGet the projection matrix of a specific stereo eye.
GetStereoViewMatrixGet the view matrix of a specific stereo eye.
RemoveAllCommandBuffersRemove all command buffers set on this camera.
RemoveCommandBufferRemove command buffer from execution at a specified place.
RemoveCommandBuffersRemove command buffers from execution at a specified place.
RenderRender the camera manually.
RenderToCubemapRender into a static cubemap from this camera.
RenderWithShaderRender the camera with shader replacement.
ResetAspectRevert the aspect ratio to the screen's aspect ratio.
ResetCullingMatrixMake culling queries reflect the camera's built in parameters.
ResetFieldOfViewReset to the default field of view.
ResetProjectionMatrixMake the projection reflect normal camera's parameters.
ResetReplacementShaderRemove shader replacement from camera.
ResetStereoProjectionMatricesUse the default projection matrix for both stereo eye. Only work in 3D flat panel display.
ResetStereoViewMatricesUse the default view matrix for both stereo eye. Only work in 3D flat panel display.
ResetWorldToCameraMatrixMake the rendering position reflect the camera's position in the scene.
ScreenPointToRayReturns a ray going from camera through a screen point.
ScreenToViewportPointTransforms position from screen space into viewport space.
ScreenToWorldPointTransforms position from screen space into world space.
SetReplacementShaderMake the camera render with shader replacement.
SetStereoProjectionMatrixSets a custom stereo projection matrix.
SetStereoViewMatrixSets a custom stereo view matrix.
SetTargetBuffersSets the Camera to render to the chosen buffers of one or more RenderTextures.
ViewportPointToRayReturns a ray going from camera through a viewport point.
ViewportToScreenPointTransforms position from viewport space into screen space.
ViewportToWorldPointTransforms position from viewport space into world space.
WorldToScreenPointTransforms position from world space into screen space.
WorldToViewportPointTransforms position from world space into viewport space.

Static Functions

GetAllCamerasFills an array of Camera with the current cameras in the scene, without allocating a new array.

Messages

OnPostRenderOnPostRender is called after a camera has finished rendering the scene.
OnPreCullOnPreCull is called before a camera culls the scene.
OnPreRenderOnPreRender is called before a camera starts rendering the scene.
OnRenderImageOnRenderImage is called after all rendering is complete to render image.
OnRenderObjectOnRenderObject is called after camera has rendered the scene.
OnWillRenderObjectOnWillRenderObject is called for each camera if the object is visible.

Delegates

CameraCallbackDelegate type for camera callbacks.

Inherited members

Variables

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledHas the Behaviour had enabled called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Functions

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Static Functions

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.