ㅈ페ㅔ
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GeppettoRunTriggerZone : MonoBehaviour
|
||||
{
|
||||
[Header("Trigger")]
|
||||
public string playerTag = "Player";
|
||||
|
||||
[Header("Geppetto")]
|
||||
public Transform geppetto;
|
||||
public Animator geppettoAnimator;
|
||||
public string runBoolName = "isRunning";
|
||||
|
||||
[Header("Move")]
|
||||
public float runSpeed = 5f;
|
||||
public float rotateSpeed = 8f;
|
||||
public float fadeDistance = 2f;
|
||||
|
||||
[Header("Fade")]
|
||||
public Image blackFadeImage;
|
||||
public float fadeDuration = 1f;
|
||||
|
||||
[Header("Scene")]
|
||||
public string nextSceneName;
|
||||
|
||||
private Transform targetPlayer;
|
||||
private bool started = false;
|
||||
private bool fading = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (blackFadeImage != null)
|
||||
{
|
||||
blackFadeImage.gameObject.SetActive(true);
|
||||
|
||||
Color c = blackFadeImage.color;
|
||||
c.a = 0f;
|
||||
blackFadeImage.color = c;
|
||||
}
|
||||
|
||||
if (geppettoAnimator != null && !string.IsNullOrEmpty(runBoolName))
|
||||
{
|
||||
geppettoAnimator.SetBool(runBoolName, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (started)
|
||||
return;
|
||||
|
||||
if (!IsPlayer(other))
|
||||
return;
|
||||
|
||||
Debug.Log("제페토 이벤트 구역 진입: " + other.name);
|
||||
|
||||
targetPlayer = other.transform;
|
||||
started = true;
|
||||
|
||||
if (geppettoAnimator != null && !string.IsNullOrEmpty(runBoolName))
|
||||
{
|
||||
geppettoAnimator.SetBool(runBoolName, true);
|
||||
}
|
||||
|
||||
Collider triggerCollider = GetComponent<Collider>();
|
||||
if (triggerCollider != null)
|
||||
{
|
||||
triggerCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!started || fading)
|
||||
return;
|
||||
|
||||
if (geppetto == null || targetPlayer == null)
|
||||
return;
|
||||
|
||||
Vector3 dir = targetPlayer.position - geppetto.position;
|
||||
dir.y = 0f;
|
||||
|
||||
float distance = dir.magnitude;
|
||||
|
||||
if (dir.sqrMagnitude > 0.001f)
|
||||
{
|
||||
Quaternion targetRotation = Quaternion.LookRotation(dir);
|
||||
geppetto.rotation = Quaternion.Slerp(
|
||||
geppetto.rotation,
|
||||
targetRotation,
|
||||
Time.deltaTime * rotateSpeed
|
||||
);
|
||||
|
||||
geppetto.position += dir.normalized * runSpeed * Time.deltaTime;
|
||||
}
|
||||
|
||||
if (distance <= fadeDistance)
|
||||
{
|
||||
StartCoroutine(FadeOutAndLoadScene());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeOutAndLoadScene()
|
||||
{
|
||||
fading = true;
|
||||
|
||||
if (geppettoAnimator != null && !string.IsNullOrEmpty(runBoolName))
|
||||
{
|
||||
geppettoAnimator.SetBool(runBoolName, false);
|
||||
}
|
||||
|
||||
float t = 0f;
|
||||
|
||||
while (t < fadeDuration)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float alpha = Mathf.Clamp01(t / fadeDuration);
|
||||
|
||||
if (blackFadeImage != null)
|
||||
{
|
||||
Color c = blackFadeImage.color;
|
||||
c.a = alpha;
|
||||
blackFadeImage.color = c;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(nextSceneName))
|
||||
{
|
||||
SceneManager.LoadScene(nextSceneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Next Scene Name이 비어있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPlayer(Collider other)
|
||||
{
|
||||
if (other.CompareTag(playerTag))
|
||||
return true;
|
||||
|
||||
if (other.transform.root.CompareTag(playerTag))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user