Camera2dFollow

From Headbone Creative
Revision as of 22:44, 14 April 2013 by Tyson Joehler (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This script is designed to be used on 2D games. Assign a target in the editor (generally the player), and it will follow the target around the world on the X and Y axis.

Contents

Public Variables

Below are all of the variables that may be changed in the editor.

Following the target

These control how the camera follows an object (movement on the X and Y axis).

target : GameObject

This is what the camera will follow. Usually, it is the player.

playerTag : String

This is the name of a tag. If the target is null when this script is started, and this string is set, the script will attempt to look up a game object with this tag and set it as the target. See: GameObject.FindWithTag

min : Vector2 and max : Vector2

These are used together, to constrain when the camera will start following the target. This allows the target to move around the middle of the screen without the camera constantly moving, if desired. The units are in pixels. If alwaysCenter is set, these values are ignored.

alwaysCenter : bool

If this is enabled, the camera will continuously adjust itself so that the player is at the middle of the screen.

followSpeed : float

This defines how fast to move the camera towards the player.

Zooming in and out

These control the camera movement on the Z axis.

canZoom : bool

If this camera can zoom in to the object or not.

minDistance : float

The minimum zoom distance.

maxDistance : float

The maximum zoom distance.

distance : float

The starting/current zoom distance.

zoomRate : float

How fast the player can zoom in or out.

zoomDampening : float

The rate at which the forward/back movement of the camera will go when the target moves.

distanceScrollAxis : string

The Input axis to query for zooming. Default: Mouse ScrollWheel

Examples

This camera is used in the Sidescroller Demo. A prefab of this camera is also provided in the toolbox.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox