Created
January 28, 2024 19:21
-
-
Save leventeren/b1a116ac0071ef8bf9749f35b4f2e948 to your computer and use it in GitHub Desktop.
CinemachineExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Cinemachine; | |
/// <summary> | |
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Z co-ordinate | |
/// </summary> | |
[ExecuteInEditMode] [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu | |
public class LockCameraZ : CinemachineExtension | |
{ | |
[Tooltip("Lock the camera's Z position to this value")] | |
public float m_ZPosition = 10; | |
protected override void PostPipelineStageCallback( | |
CinemachineVirtualCameraBase vcam, | |
CinemachineCore.Stage stage, ref CameraState state, float deltaTime) | |
{ | |
if (stage == CinemachineCore.Stage.Body) | |
{ | |
var pos = state.RawPosition; | |
pos.z = m_ZPosition; | |
state.RawPosition = pos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment