2025-01-29 19:36:25 -05:00

35 lines
938 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
public class MainMenuCameraMove : MonoBehaviour
{
public Vector3 startPosition; // Starting position of the camera
public Vector3 targetPosition; // Final position (where the player is centered)
public float moveDuration = 2f; // How long the camera takes to move
private float elapsedTime = 0f;
private bool shouldMove = true;
void Start()
{
// Set the cameras starting position
transform.position = startPosition;
}
void Update()
{
if (shouldMove)
{
elapsedTime += Time.deltaTime;
// Calculate smooth progress using SmoothStep
float t = Mathf.SmoothStep(0f, 1f, elapsedTime / moveDuration);
transform.position = Vector3.Lerp(startPosition, targetPosition, t);
if (elapsedTime >= moveDuration)
{
shouldMove = false;
}
}
}
}