Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

Camera

Switch to Manual

Namespace: UnityEngine

/

Inherits from: Behaviour

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 (eg. 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).

Variables

actualRenderingPathActually used rendering path (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).
clearFlagsHow the camera clears the background.
cullingMaskThis is used to render parts of the scene selectively.
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.
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.
renderingPathRendering path.
stereoConvergenceDistance to a point where virtual eyes converge.
stereoEnabledStereoscopic rendering.
stereoSeparationDistance between the virtual eyes.
targetTextureDestination render texture (Unity Pro only).
transparencySortModeTransparent object sorting mode.
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.

Functions

CalculateObliqueMatrixCalculates and returns oblique near-plane projection matrix.
CopyFromMakes this camera's settings match other camera.
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.
ResetProjectionMatrixMake the projection reflect normal camera's parameters.
ResetReplacementShaderRemove shader replacement from camera.
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.
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 once for each camera if the object is visible.

Inherited members

Variables

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
animationThe Animation attached to this GameObject (null if there is none attached).
audioThe AudioSource attached to this GameObject (null if there is none attached).
cameraThe Camera attached to this GameObject (null if there is none attached).
colliderThe Collider attached to this GameObject (null if there is none attached).
collider2DThe Collider2D component attached to the object.
constantForceThe ConstantForce attached to this GameObject (null if there is none attached).
gameObjectThe game object this component is attached to. A component is always attached to a game object.
guiTextThe GUIText attached to this GameObject (null if there is none attached).
guiTextureThe GUITexture attached to this GameObject (Read Only). (null if there is none attached).
hingeJointThe HingeJoint attached to this GameObject (null if there is none attached).
lightThe Light attached to this GameObject (null if there is none attached).
networkViewThe NetworkView attached to this GameObject (Read Only). (null if there is none attached).
particleEmitterThe ParticleEmitter attached to this GameObject (null if there is none attached).
particleSystemThe ParticleSystem attached to this GameObject (null if there is none attached).
rendererThe Renderer attached to this GameObject (null if there is none attached).
rigidbodyThe Rigidbody attached to this GameObject (null if there is none attached).
rigidbody2DThe Rigidbody2D that is attached to the Component's GameObject.
tagThe tag of this game object.
transformThe Transform attached to this GameObject (null if there is none attached).
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

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. You are strongly recommended to use Destroy instead.
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 if two objects refer to the same.