Railcam2D
public class Railcam2D.Railcam2D;
This is the Railcam 2D Component that controls camera movement.
See the Railcam 2D Component user guide for more information.
Public Members
- Activate()
- Active
- AddTarget(Transform)
- AddTarget(Transform, float, float)
- AdjustedTargetPosition
- ClearTargets()
- ConnectRails()
- Deactivate()
- DisconnectRails()
- FindRails()
- Move(float)
- Offset
- RailsConnected
- RemoveTarget(Transform)
- Smooth
- TargetPosition
- Targets
- UpdateMethod
- UpdateTargetPosition()
Activate()
public void Activate();
Member | Method |
Returns | void |
A method that sets Active
to true
.
Active
[RangeAttribute(0f, 1f)]
public bool Active = true;
Member | Field |
Type | bool |
Defaults To | true |
A bool
that determines whether the Railcam 2D component has control of the camera (true
) or not (false
).
If true
, Railcam 2D will attempt to update the camera's position on every update. The update method used is determined by the value for UpdateMethod
. If false
, Railcam 2D does not effect camera position.
AddTarget(Transform)
public void AddTarget(Transform transform);
Member | Method |
Returns | void |
A method that allows a new target to be added to the Targets
list.
Parameters
Name | Type |
transform |
UnityEngine.Transform |
The transform
parameter is the Transform
of the new target object.
AddTarget(Transform, float, float)
public void AddTarget(Transform transform, float influenceX, float influenceY);
Member | Method |
Returns | void |
A method that allows a new target to be added to the Targets
list with the ability to specify the target's influence on camera position.
Parameters
Name | Type |
transform |
UnityEngine.Transform |
influenceX |
float |
influenceY |
float |
The transform
parameter is the Transform
of the new target object.
The influenceX
parameter is a float
that determines the amount the camera's position is effected by the target's position along the x-axis.
The influenceY
parameter is a float
that determines the amount the camera's position is effected by the target's position along the y-axis.
See the CameraTarget documentation for more details.
AdjustedTargetPosition
public Vector2 AdjustedTargetPosition { get; }
Member | Property |
Type | UnityEngine.Vector2 |
Accessors | get |
A Vector2
that represents the position the camera is moved toward.
This is the point the camera will be eventually be positioned at if the TargetPosition
remains constant. This value is the TargetPosition
but adjusted to use Offset
and rail calculations.
ClearTargets()
public void ClearTargets();
Member | Method |
Returns | void |
A method that removes all targets from the Targets
list.
ConnectRails()
public void ConnectRails();
Member | Method |
Returns | void |
A method that sets RailsConnected
to true
.
Deactivate()
public void Deactivate();
Member | Method |
Returns | void |
A method that sets Active
to false
.
DisconnectRails()
public void DisconnectRails();
Member | Method |
Returns | void |
A method that sets RailsConnected
to true
.
FindRails()
public void FindRails();
Member | Method |
Returns | void |
A method that finds all Rails in the scene and caches them in the Railcam 2D component.
The Railcam 2D component executes this method once on initialization.
Caching Rails vastly improves the efficiency of camera position calculation as Rails do not need to be found on every call to update. However, if a Rail component is added to the scene after the Railcam 2D component has been initialized, Railcam 2D will not know the Rail exists and will not include it when calculating camera position.
This method should be called whenever a Rail is added to a scene during runtime.
Move(float)
public void Move(float deltaTime);
Member | Method |
Returns | void |
A method that calculates a new camera position and moves the game object.
This method is called on every update, determined by the value for UpdateMethod
.
If UpdateMethod
is set to ManualUpdate
, this method must be called manually to move the camera.
Parameters
Name | Type |
deltaTime |
float |
The deltaTime
parameter is a float
that determines the time since the camera was last moved.
This is used to calculate the smoothed position of the camera.
If UpdateMethod
is LateUpdate
, this method gets called with UnityEngine.Time.deltaTime
.
If UpdateMethod
is FixedUpdate
, this method gets called with UnityEngine.Time.fixedDeltaTime
.
Offset
public Vector2 Offset = new Vector2(0, 0);
Member | Field |
Type | UnityEngine.Vector2 |
Defaults To | new Vector2(0, 0) |
A Vector2
that offsets the camera from its target position along the x-axis (Offset.x
) and y-axis (Offset.y
).
Values are in world units.
RailsConnected
public bool RailsConnected = true;
Member | Field |
Type | bool |
Defaults To | true |
A bool
that determines if Railcam 2D uses Rails to calculate camera position (true
) or allows the camera to move freely (false
).
If false
, the camera will be positioned based on the target position alone.
RemoveTarget(Transform)
public void RemoveTarget(Transform transform);
Member | Method |
Returns | void |
A method that removes a specified target from the Targets
list.
Parameters
Name | Type |
transform |
UnityEngine.Transform |
The transform
parameter is the Transform
of the target object that is to be removed from the list of targets.
Smooth
public Vector2 Smooth = new Vector2(0.25f, 0.25f);
Member | Field |
Type | UnityEngine.Vector2 |
Defaults To | new Vector2(0.25f, 0.25f) |
A Vector2
that determines the degree to which camera movement is smoothed along the x-axis (Offset.x
) and y-axis (Offset.y
).
A value of 0f
removes smoothing, and means the camera will always be positioned at the AdjustedTargetPosition
. A value above 0f
will smooth the movement of the camera.
A larger value reduces the camera's acceleration toward its target position.
TargetPosition
public Vector2 TargetPosition { get; }
Member | Property |
Type | UnityEngine.Vector2 |
Accessors | get |
A Vector2
that represents the combined position of all camera targets in the Targets
list.
This value does not take into account Offset
or rail calculations. See AdjustedTargetPosition
for a value that represents the position the camera moves toward.
Targets
public List<CameraTarget> Targets = new List<CameraTarget>();
Member | Field |
Type | List<Railcam2D.CameraTarget> |
Defaults To | new List<Railcam2D.CameraTarget>() |
A list of CameraTarget
s used to calculate a single TargetPosition
for the camera.
See the CameraTarget documentation for more information.
UpdateMethod
public UpdateMethod UpdateMethod = UpdateMethod.LateUpdate;
Member | Field |
Type | Railcam2D.UpdateMethod |
Defaults To | Railcam2D.UpdateMethod.LateUpdate |
An UpdateMethod
enum value that determines the Unity update method used to calculate camera position.
UpdateTargetPosition()
public void UpdateTargetPosition();
Member | Method |
Returns | void |
A method that recalculates the camera's TargetPosition
and AdjustedTargetPosition
.
This is called internally in the Move
method before the game object is moved.