Camera
Inherits from: Behaviour
Camera in Unity acts as the player's viewpoint into the game world, capturing scenes much like a real camera. It defines the field of view, perspective, and what is visible on the screen. Cameras can transform between world and screen space, control projection settings for depth and perspective, specify rendering settings, and manage culling properties. For comprehensive functionalities, explore Unity's Camera documentation.
Properties
Defines the closest distance at which the Camera starts rendering objects.
Sets the maximum distance up to which the Camera renders objects in the scene.
Manages the vertical extent of the scene visible at any moment, measured in degrees.
Controls if the Camera uses High Dynamic Range rendering for enhanced visual details.
Enables or disables Multi-Sample Anti-Aliasing for smoother image edges.
Allows dynamic resolution adjustment for performance optimization.
Forces Camera's view to always render to a texture for advanced image processing.
Defines the size of the view in world units for Orthographic Cameras.
Toggles between Perspective and Orthographic modes for the Camera.
Custom axis for sorting transparent objects when using Custom Axis mode.
Specifies the Camera's depth in the rendering order.
Sets the aspect ratio (width/height) for the Camera.
Provides the Camera's velocity, useful for motion blur effects.
Bit mask for rendering GameObjects on specific Layers.
Bit mask to selectively ignore GameObjects when sending events.
Uses spherical bounds for layer culling computation when enabled.
Bit mask override for Scene culling on this Camera.
Determines if Unity performs occlusion culling for this Camera.
Custom projection matrix for the Camera to adjust rendering.
Sets the background color for the Camera's view.
Clears the stencil buffer after lighting pass as an optimization.
Enables physical camera settings to simulate real camera properties.
Simulates the ISO setting of a physical camera, affecting image brightness and noise.
Mimics a camera's shutter speed, influencing exposure and motion blur.
Emulates the aperture of a physical camera, impacting light intake and depth of field.
Adjusts the distance to the focus plane, useful for depth of field effects.
Represents the focal length of the camera lens, affecting the field of view.
Sets the number of diaphragm blades, affecting the shape of out-of-focus areas.
Simulates lens curvature, affecting perspective distortion in the rendered image.
Determines the clipping level for light entering the camera, affecting edge brightness.
Creates anamorphic lens effects by compressing the image in one dimension.
Imitates the physical dimensions of the camera sensor, affecting the angle of view.
Allows shifting the lens in relation to the sensor, correcting for keystone distortion.
Specifies the Camera's viewport rectangle, controlling which part of the screen it occupies.
Defines the rectangle, in pixels, that the Camera renders to on the screen.
Gives the width in pixels of the Camera's rendering area.
Provides the height in pixels of the Camera's rendering area.
Gets the width of the Camera's image after applying the scaling factor.
Retrieves the height of the Camera's image with the scaling factor applied.
Sets the display for the Camera's output, useful for multi-display setups.
Provides a matrix transforming from camera space to world space.
Allows setting a custom transformation from world space to camera space.
Offers a custom projection matrix for perspective transformations.
Gives a projection matrix without jittering for anti-aliasing.
Decides whether to use a jittered projection matrix for rendering transparent objects.
Holds the matrix from multiplying the previous frame's projection matrix by its world-to-camera matrix, useful for effects needing historical comparison.
Indicates if stereoscopic rendering is enabled for creating 3D effects.
Adjusts the distance between the stereo camera's views to alter the 3D effect's intensity.
Sets the point where the left and right views converge, affecting the depth of the 3D scene.
Checks if the view matrices for VR rendering fall within a tolerance for efficient culling.
Returns the total number of command buffers attached to the Camera, for extending rendering.
Accesses the main Camera in the scene, designated by the 'MainCamera' tag.
Retrieves the currently rendering Camera, useful for effects and scripts during rendering.
Gives the count of all enabled Cameras within the Scene.
Specifies the minimum logical aperture size for cameras, constraining physical camera simulations.
Defines the maximum logical aperture size for camera simulations, affecting depth of field and light intake.
Indicates the minimum number of aperture blades for simulating camera bokeh effects.
Sets the maximum number of aperture blades for detailed bokeh simulation in camera effects.
Methods
Converts a point from screen space into world space for this Camera, useful for interaction with game objects.
Transforms a world space point to screen space, allowing UI alignment or visibility checks.
Creates a ray from the Camera through a screen point, primarily for object selection via raycasting.
Resets all Camera settings to their defaults, useful for reinitializing camera properties.
Returns
void
Reverts the Camera's transparency sort settings to the default state.
Returns
void
Resets the Camera's aspect ratio to the screen's aspect ratio, undoing any custom aspect ratio settings.
Returns
void
Resets the Camera's culling matrix to the default, useful for undoing custom culling adjustments.
Returns
void
Removes any replacement shader from the Camera, returning to standard rendering.
Returns
void
Calculates the field of view based on gate fitting, useful for matching physical camera settings.
Returns
number
The calculated field of view.
Determines the lens shift required based on gate fitting, aiding in accurate camera simulation.
Returns
The required lens shift.
Resets the Camera's world-to-camera matrix to the identity matrix, clearing any transformations.
Returns
void
Reverts the Camera's projection matrix to default, useful for standard perspective restoration.
Returns
void
Creates a custom projection matrix for oblique near-plane clipping, useful for mirror reflections or water surfaces.
Transforms a point from screen space to normalized viewport space.
Converts a point from normalized viewport space to screen space.
Resets the stereo projection matrices for left and right eyes to the default values.
Returns
void
Reverts the stereo view matrices for the left and right eyes to Unity's defaults.
Returns
void
Forces immediate rendering of the scene from this Camera's perspective.
Returns
void
Renders the scene immediately without restoring the Camera's state afterwards.
Returns
void
Copies settings from another Camera, including all properties and transformation matrices.
Parameters
other
CameraThe source Camera to copy from.
Returns
void
Deletes all command buffers attached to this Camera.
Returns
void
Converts focal length to vertical field of view for the Camera's sensor size.
Parameters
focalLength
number
The focal length to convert.
sensorSize
number
The vertical size of the sensor.
Returns
number
The calculated vertical field of view.
Calculates the focal length from a given vertical field of view and sensor size.
Parameters
fieldOfView
number
The vertical field of view to convert.
sensorSize
number
The vertical size of the sensor.
Returns
number
The focal length corresponding to the given field of view.
Converts a horizontal field of view to a vertical field of view based on the aspect ratio.
Parameters
horizontalFieldOfView
number
The horizontal field of view to convert.
aspectRatio
number
The aspect ratio of the camera.
Returns
number
The vertical field of view.
Converts a vertical field of view to a horizontal field of view based on the aspect ratio.
Parameters
verticalFieldOfView
number
The vertical field of view to convert.
aspectRatio
number
The aspect ratio of the camera.
Returns
number
The horizontal field of view.
Sets a specified Camera as the current active Camera, useful for dynamic camera switching.
Parameters
cur
CameraThe Camera to set as current.
Returns
void
Updated 6 months ago