Camera Manual     Reference     Scripting  
Scripting > Runtime Classes > Camera
Camera Inherits from Behaviour

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.

Variables
fieldOfView

The field of view of the camera in degrees.

nearClipPlane

The near clipping plane distance.

farClipPlane

The far clipping plane distance.

renderingPath

Rendering path.

actualRenderingPath

Actually used rendering path (Read Only).

orthographicSize

Camera's half-size when in orthographic mode.

orthographic

Is the camera orthographic (true) or perspective (false)?

depth

Camera's depth in the camera rendering order.

aspect

The aspect ratio (width divided by height).

cullingMask

This is used to render parts of the scene selectively.

backgroundColor

The color with which the screen will be cleared.

rect

Where on the screen is the camera rendered in normalized coordinates.

pixelRect

Where on the screen is the camera rendered in pixel coordinates.

targetTexture

Destination render texture (Unity Pro only).

pixelWidth

How wide is the camera in pixels (Read Only).

pixelHeight

How tall is the camera in pixels (Read Only).

cameraToWorldMatrix

Matrix that transforms from camera space to world space (Read Only).

worldToCameraMatrix

Matrix that transforms from world to camera space.

projectionMatrix

Set a custom projection matrix.

velocity

Get the world-space speed of the camera (Read Only).

clearFlags

How the camera clears the background.

layerCullDistances

Per-layer culling distances.

depthTextureMode

How and if camera generates a depth texture.

Functions
ResetWorldToCameraMatrix

Make the rendering position reflect the camera's position in the scene.

ResetProjectionMatrix

Make the projection reflect normal camera's parameters.

ResetAspect

Revert the aspect ratio to the screen's aspect ratio.

WorldToScreenPoint

Transforms position from world space into screen space.

WorldToViewportPoint

Transforms position from world space into viewport space.

ViewportToWorldPoint

Transforms position from viewport space into world space.

ScreenToWorldPoint

Transforms position from screen space into world space.

ScreenToViewportPoint

Transforms position from screen space into viewport space.

ViewportToScreenPoint

Transforms position from viewport space into screen space.

ViewportPointToRay

Returns a ray going from camera through a viewport point.

ScreenPointToRay

Returns a ray going from camera through a screen point.

Render

Render the camera manually.

RenderWithShader

Render the camera with shader replacement.

SetReplacementShader

Make the camera render with shader replacement.

ResetReplacementShader

Remove shader replacement from camera.

RenderToCubemap

Render into a cubemap from this camera.

CopyFrom

Makes this camera's settings match other camera.

Messages Sent
OnPreCull

OnPreCull is called before a camera culls the scene.

OnPreRender

OnPreRender is called before a camera starts rendering the scene.

OnPostRender

OnPostRender is called after a camera has finished rendering the scene.

OnRenderImage

OnRenderImage is called after all rendering is complete to render image

OnRenderObject

OnRenderObject is called after camera has rendered the scene.

OnWillRenderObject

OnWillRenderObject is called once for each camera if the object is visible.

Class Variables
main

The first enabled camera tagged "MainCamera" (Read Only).

current

The camera we are currently rendering with, for low-level render control only (Read Only).

allCameras

Returns all enabled cameras in the scene.

Inherited members
Inherited Variables
enabled

Enabled Behaviours are Updated, disabled Behaviours are not.

transform

The Transform attached to this GameObject (null if there is none attached).

rigidbody

The Rigidbody attached to this GameObject (null if there is none attached).

camera

The Camera attached to this GameObject (null if there is none attached).

light

The Light attached to this GameObject (null if there is none attached).

animation

The Animation attached to this GameObject (null if there is none attached).

constantForce

The ConstantForce attached to this GameObject (null if there is none attached).

renderer

The Renderer attached to this GameObject (null if there is none attached).

audio

The AudioSource attached to this GameObject (null if there is none attached).

guiText

The GUIText attached to this GameObject (null if there is none attached).

networkView

The NetworkView attached to this GameObject (Read Only). (null if there is none attached)

guiTexture

The GUITexture attached to this GameObject (Read Only). (null if there is none attached)

collider

The Collider attached to this GameObject (null if there is none attached).

hingeJoint

The HingeJoint attached to this GameObject (null if there is none attached).

particleEmitter

The ParticleEmitter attached to this GameObject (null if there is none attached).

gameObject

The game object this component is attached to. A component is always attached to a game object.

tag

The tag of this game object.

name

The name of the object.

hideFlags

Should the object be hidden, saved with the scene or modifiable by the user?

Inherited Functions
GetComponent

Returns the component of Type type if the game object has one attached, null if it doesn't.

GetComponent.<T>

GetComponent

Returns the component with name type if the game object has one attached, null if it doesn't.

GetComponentInChildren

Returns the component of Type type in the GameObject or any of its children using depth first search.

GetComponentInChildren.<T>

GetComponentsInChildren

Returns all components of Type type in the GameObject or any of its children.

GetComponentsInChildren.<T>

GetComponents

Returns all components of Type type in the GameObject.

GetComponents.<T>

CompareTag

Is this game object tagged tag?

SendMessageUpwards

Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour

SendMessage

Calls the method named methodName on every MonoBehaviour in this game object.

BroadcastMessage

Calls the method named methodName on every MonoBehaviour in this game object or any of its children.

GetInstanceID

Returns the instance id of the object.

ToString

Returns the name of the game object.

Inherited Class Functions
operator bool

Does the object exist?

Instantiate

Clones the object original and returns the clone.

Instantiate.<T>

Destroy

Removes a gameobject, component or asset.

DestroyImmediate

Destroys the object obj immediately. It is strongly recommended to use Destroy instead.

FindObjectsOfType

Returns a list of all active loaded objects of Type type.

FindObjectOfType

Returns the first active loaded object of Type type.

operator ==

Compares if two objects refer to the same

operator !=

Compares if two objects refer to a different object

DontDestroyOnLoad

Makes the object target not be destroyed automatically when loading a new scene.