FirstPersonState.cs
Description
The script to be used when the camera is in their first-person state.
Script
using Unity.Cinemachine;
namespace Cameras.FSM.States
{
public class FirstPersonState : CameraState
{
private bool _isChangingPerspective;
public FirstPersonState(string stateName, CameraStateMachine stateMachine, CameraController cameraController, CinemachineCamera stateCamera) : base(stateMachine, cameraController, stateCamera)
{
StateMachine = stateMachine;
CameraController = cameraController;
StateCamera = stateCamera;
}
public override void LogicUpdate()
{
base.LogicUpdate();
if (StateMachine.CurrentState.IsChangingPerspective)
StateMachine.ChangeState(CameraController.ThirdPersonState);
}
}
}
Public Methods
- FirstPersonState()
Stores references to the required components by the script.
- LogicUpdate()
Checks if the camera is changing perspective. If so then change the camera state machine to the third-person state.
Variables
- _isChangingPerspective
Is the camera currently changing perspective
Last modified: 30 April 2024