ReplayPuzzleGame/Assets/Resources/Scripts/Utility/CameraEffect.cs

77 lines
1.9 KiB
C#
Raw Normal View History

2026-02-10 08:18:34 +00:00
using System;
using System.Collections;
using UnityEngine;
public class CameraEffect : MonoBehaviour
{
private Transform target;
2026-02-08 13:13:32 +00:00
2026-02-10 08:18:34 +00:00
// 카메라 따라가는 속도 조절
[SerializeField] float smoothTime = 0.3f;
// 아래키로 화면 내릴 수 있는 수치
2026-02-08 13:13:32 +00:00
[SerializeField] private float lookDownAmount = 4f;
2026-02-10 08:18:34 +00:00
// 오프셋
[SerializeField] private Vector3 offset = new Vector3(0, 0, -10f);
private float defaultYOffset;
private Vector3 _velocity = Vector3.zero;
2026-02-08 10:29:37 +00:00
private void Start()
{
2026-02-08 13:13:32 +00:00
defaultYOffset = offset.y;
2026-02-10 08:18:34 +00:00
target = GameObject.FindGameObjectWithTag("Player").transform;
}
private void LateUpdate()
{
if (target == null)
{
return;
}
2026-02-08 13:13:32 +00:00
2026-02-10 08:18:34 +00:00
Vector3 targetPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _velocity, smoothTime);
}
public void SetTarget(Transform target)
{
this.target = target;
2026-02-08 10:29:37 +00:00
}
2026-02-10 08:18:34 +00:00
// 아래보는 키 눌렀을때 왔다 갔다
2026-02-08 13:13:32 +00:00
public void SetLookDown(bool isLookingDown)
{
if (isLookingDown)
{
offset.y = defaultYOffset - lookDownAmount;
}
else
{
offset.y = defaultYOffset;
}
}
2026-02-10 08:18:34 +00:00
public void PlayPreViewSequence(Action onComplete)
2026-02-05 04:42:44 +00:00
{
2026-02-10 08:18:34 +00:00
StartCoroutine(PreviewSequence(onComplete));
2026-02-05 04:42:44 +00:00
}
2026-02-10 08:18:34 +00:00
public IEnumerator PreviewSequence(Action onComplete)
2026-02-05 04:42:44 +00:00
{
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;
2026-02-10 08:18:34 +00:00
yield return new WaitForSeconds(1f);
onComplete?.Invoke();
2026-02-05 04:42:44 +00:00
}
}