Skip to content

Commit

Permalink
Merge pull request #105 from 2024FALL-SWPP/dongho/EndingScene
Browse files Browse the repository at this point in the history
EndingScene
  • Loading branch information
anordongho authored Nov 21, 2024
2 parents c55b77c + 80bce58 commit 537f436
Show file tree
Hide file tree
Showing 20 changed files with 50,486 additions and 157 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified 302/.DS_Store
Binary file not shown.
Binary file modified 302/Assets/.DS_Store
Binary file not shown.
48,781 changes: 48,654 additions & 127 deletions 302/Assets/Scenes/GameEndingScene.unity

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 302/Assets/Scenes/GameEndingScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions 302/Assets/Scripts/CreditScroll.cs
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");
}
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/CreditScroll.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions 302/Assets/Scripts/EndingDoor.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/EndingDoor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions 302/Assets/Scripts/EndingManager.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/EndingManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 302/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GameManager : MonoBehaviour
[SerializeField] private bool currentStageClear = false; // 현재 스테이지 클리어 여부
[SerializeField] private ClockController clockController;
private const string DEFAULT_SCENE = "DefaultGameScene";
private const string ENDING_SCENE = "EndingScene";
private const string ENDING_SCENE = "GameEndingScene";
public enum GameState
{
Playing,
Expand Down
Binary file added 302/Assets/Sounds/automatic-door.mp3
Binary file not shown.
22 changes: 22 additions & 0 deletions 302/Assets/Sounds/automatic-door.mp3.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added 302/Assets/Sounds/long-goodbye.mp3
Binary file not shown.
22 changes: 22 additions & 0 deletions 302/Assets/Sounds/long-goodbye.mp3.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added 302/Assets/Sounds/schoolbell.mp3
Binary file not shown.
22 changes: 22 additions & 0 deletions 302/Assets/Sounds/schoolbell.mp3.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 537f436

Please sign in to comment.