Rasagar/Library/PackageCache/com.unity.cinemachine/Samples~/Cinemachine Example Scenes/Scenes/BossCamera/CustomLockCameraY.cs

28 lines
858 B
C#
Raw Normal View History

2024-08-26 13:07:20 -07:00
using UnityEngine;
namespace Cinemachine.Examples
{
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Y co-ordinate
/// </summary>
[ExecuteAlways]
[SaveDuringPlay]
[AddComponentMenu("")] // Hide in menu
public class CustomLockCameraY : CinemachineExtension
{
[Tooltip("Lock the camera's Y position to this value")]
public float m_YPosition = 10;
protected override void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Finalize)
{
var pos = state.RawPosition;
pos.y = m_YPosition;
state.RawPosition = pos;
}
}
}
}