ReplayPuzzleGame/Assets/Scripts/Utility/CameraEffect.cs

52 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections;
using UnityEngine;
public class CameraEffect : MonoBehaviour
{
private Transform target;
2026-02-08 10:29:37 +00:00
[SerializeField] Transform cameraSpawnPoint;
public float smoothTime = 0.3f;
public Vector3 offset = new Vector3(0, 0, -10f);
private Vector3 _velocity = Vector3.zero;
2026-02-08 10:29:37 +00:00
private void Start()
{
gameObject.transform.position = cameraSpawnPoint.position;
}
private void Update()
{
if (target == null)
{
target = GameObject.FindGameObjectWithTag("Player")?.transform;
return;
}
Vector3 targetPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _velocity, smoothTime);
}
2026-02-05 04:42:44 +00:00
public void PlayPreView()
{
StartCoroutine(PlayStartSequence());
}
2026-02-05 04:42:44 +00:00
public IEnumerator PlayStartSequence()
{
Transform player = GameObject.FindGameObjectWithTag("Player").transform;
target = player;
yield return new WaitForSeconds(2f);
GameObject cheese = GameObject.FindGameObjectWithTag("Cheese");
if (cheese != null)
{
target = cheese.transform;
yield return new WaitForSeconds(2f);
}
target = player;
yield return new WaitForSeconds(2f);
GameManager.instance.PlayerAlive();
}
}