-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
EndingScene
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using UnityEngine.SceneManagement; | ||
using System.Collections; | ||
|
||
public class CreditScroll : MonoBehaviour | ||
{ | ||
[SerializeField] private float scrollSpeed = 50f; | ||
[SerializeField] private float startY = -800f; | ||
[SerializeField] private float endY = 800f; | ||
[SerializeField] private Image fadeImage; // 페이드아웃용 검은 이미지 | ||
[SerializeField] private float fadeSpeed = 1f; // 페이드 속도 | ||
|
||
private RectTransform rectTransform; | ||
private bool isEnding = false; | ||
|
||
private void Start() | ||
{ | ||
rectTransform = GetComponent<RectTransform>(); | ||
|
||
// 시작 위치 설정 | ||
Vector3 pos = rectTransform.anchoredPosition; | ||
pos.y = startY; | ||
rectTransform.anchoredPosition = pos; | ||
|
||
// 페이드 이미지 초기화 | ||
if(fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = 0; | ||
fadeImage.color = c; | ||
} | ||
} | ||
|
||
private void Update() | ||
{ | ||
if(!isEnding) | ||
{ | ||
// 위로 스크롤 | ||
Vector3 pos = rectTransform.anchoredPosition; | ||
pos.y += scrollSpeed * Time.deltaTime; | ||
rectTransform.anchoredPosition = pos; | ||
|
||
// 끝까지 올라갔는지 체크 | ||
if(pos.y >= endY && !isEnding) | ||
{ | ||
isEnding = true; | ||
StartCoroutine(EndCredits()); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerator EndCredits() | ||
{ | ||
// 잠시 대기 | ||
yield return new WaitForSeconds(1f); | ||
|
||
// 페이드 아웃 (검은색) | ||
float alpha = 0; | ||
while (alpha < 1f) | ||
{ | ||
alpha += Time.deltaTime * fadeSpeed; | ||
if(fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = alpha; | ||
fadeImage.color = c; | ||
} | ||
yield return null; | ||
} | ||
|
||
// 잠시 대기 | ||
yield return new WaitForSeconds(1f); | ||
|
||
// GameStartingScene으로 전환 | ||
SceneManager.LoadScene("GameStartingScene"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class EndingDoor : MonoBehaviour | ||
{ | ||
[SerializeField] private Image fadeImage; | ||
[SerializeField] private float fadeSpeed = 2f; | ||
[SerializeField] private GameObject creditUI; | ||
[SerializeField] private AudioSource endingAudioSource; | ||
[SerializeField] private AudioClip endingMusic; | ||
[SerializeField] private AudioSource doorSoundSource; | ||
[SerializeField] private AudioClip doorOpenSound; | ||
[SerializeField] private float musicDuration = 5f; // 음악 재생 시간 | ||
[SerializeField] private float musicFadeSpeed = 1f; // 페이드아웃 속도 | ||
|
||
private void Start() | ||
{ | ||
if (creditUI != null) | ||
creditUI.SetActive(false); | ||
|
||
if (fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = 0; | ||
fadeImage.color = c; | ||
} | ||
} | ||
|
||
private void OnTriggerEnter(Collider other) | ||
{ | ||
if (other.CompareTag("Player")) | ||
{ | ||
StartCoroutine(StartEnding(other.gameObject)); | ||
} | ||
} | ||
|
||
private IEnumerator StartEnding(GameObject player) | ||
{ | ||
if (doorSoundSource != null && doorOpenSound != null) | ||
{ | ||
doorSoundSource.clip = doorOpenSound; | ||
doorSoundSource.Play(); | ||
} | ||
|
||
yield return new WaitForSeconds(0.5f); | ||
|
||
float alpha = 0; | ||
while (alpha < 1f) | ||
{ | ||
alpha += Time.deltaTime * fadeSpeed; | ||
if (fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = alpha; | ||
fadeImage.color = c; | ||
} | ||
yield return null; | ||
} | ||
|
||
PlayerController playerController = player.GetComponent<PlayerController>(); | ||
if (playerController != null) | ||
{ | ||
Destroy(playerController); | ||
} | ||
|
||
yield return new WaitForSeconds(1f); | ||
|
||
if (endingAudioSource != null && endingMusic != null) | ||
{ | ||
endingAudioSource.clip = endingMusic; | ||
endingAudioSource.volume = 1f; | ||
endingAudioSource.Play(); | ||
StartCoroutine(FadeOutMusic()); | ||
} | ||
|
||
if (creditUI != null) | ||
creditUI.SetActive(true); | ||
} | ||
|
||
private IEnumerator FadeOutMusic() | ||
{ | ||
// 설정된 시간만큼 대기 | ||
yield return new WaitForSeconds(musicDuration); | ||
|
||
// 페이드아웃 | ||
float volume = 1f; | ||
while (volume > 0) | ||
{ | ||
volume -= Time.deltaTime * musicFadeSpeed; | ||
endingAudioSource.volume = Mathf.Max(0, volume); | ||
yield return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class EndingManager : MonoBehaviour | ||
{ | ||
[SerializeField] private GameObject clockCamera; | ||
[SerializeField] private AudioSource endingAudioSource; | ||
[SerializeField] private AudioClip endingMusic; | ||
[SerializeField] private float moveSpeed = 0.001f; | ||
[SerializeField] private GameObject player; | ||
[SerializeField] private Image fadeImage; | ||
[SerializeField] private float fadeSpeed = 1f; | ||
|
||
private Vector3 targetPosition = new Vector3(-15.3f, 7.25f, 0f); | ||
private bool isMoving = false; | ||
private float lerpTime = 0f; | ||
|
||
public void OnEnable() | ||
{ | ||
if(fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = 0; | ||
fadeImage.color = c; | ||
} | ||
StartEnding(); | ||
} | ||
|
||
public void StartEnding() | ||
{ | ||
isMoving = true; | ||
lerpTime = 0f; | ||
|
||
if (endingAudioSource != null && endingMusic != null) | ||
{ | ||
endingAudioSource.clip = endingMusic; | ||
endingAudioSource.Play(); | ||
} | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (isMoving) | ||
{ | ||
lerpTime += Time.deltaTime * moveSpeed; | ||
clockCamera.transform.position = Vector3.Lerp(clockCamera.transform.position, targetPosition, lerpTime); | ||
|
||
if (Vector3.Distance(clockCamera.transform.position, targetPosition) < 0.01f) | ||
{ | ||
isMoving = false; | ||
clockCamera.transform.position = targetPosition; | ||
StartCoroutine(SwitchToPlayerWithFade()); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerator SwitchToPlayerWithFade() | ||
{ | ||
// 완전히 페이드 아웃 | ||
float alpha = 0; | ||
while (alpha < 1f) | ||
{ | ||
alpha += Time.deltaTime * fadeSpeed; | ||
if(fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = alpha; | ||
fadeImage.color = c; | ||
} | ||
yield return null; | ||
} | ||
|
||
// 완전히 어두워진 후에 전환 | ||
if(player != null) | ||
player.SetActive(true); | ||
if(clockCamera != null) | ||
clockCamera.SetActive(false); | ||
|
||
yield return new WaitForSeconds(1f); | ||
|
||
// 페이드 인 | ||
while (alpha > 0) | ||
{ | ||
alpha -= Time.deltaTime * fadeSpeed; | ||
if(fadeImage != null) | ||
{ | ||
Color c = fadeImage.color; | ||
c.a = alpha; | ||
fadeImage.color = c; | ||
} | ||
yield return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.