You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ReactRacetrack/Assets/Scripts/DollyCameraTapMover.cs

38 lines
995 B
C#

using UnityEngine;
using Cinemachine;
using DG.Tweening;
public class DollyCameraTapMover : MonoBehaviour
{
public CinemachineDollyCart dollyCart;
public float moveDelta = 0.0005f; // super small movement
public float moveDuration = 0.1f;
private Tween currentTween;
void Update()
{
if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && currentTween == null)
{
MoveCameraSmooth();
}
}
void MoveCameraSmooth()
{
if (dollyCart == null) return;
float target = dollyCart.m_Position + moveDelta;
// Wrap if in normalized
if (dollyCart.m_PositionUnits == CinemachinePathBase.PositionUnits.Normalized && target > 1f)
target -= 1f;
currentTween = DOTween.To(
() => dollyCart.m_Position,
x => dollyCart.m_Position = x,
target,
moveDuration
).SetEase(Ease.OutSine).OnComplete(() => currentTween = null);
}
}