Files
Barrack-Unity/Assets/Scripts/GameOver/ScoreChecker.cs
T

63 lines
1.2 KiB
C#
Raw Normal View History

2026-07-18 23:30:43 -04:00
using UnityEngine;
using System.Collections;
public class ScoreChecker : MonoBehaviour
{
public AudioSource winSound;
public AudioSource loseSound;
public Fader fadeOut;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
2026-07-28 01:06:41 -04:00
public void ResetFader()
2026-07-18 23:30:43 -04:00
{
2026-07-28 01:06:41 -04:00
Invoke(nameof(CheckScore), 0.5f);
2026-07-18 23:30:43 -04:00
}
private IEnumerator PlayAudioThenActivateGameObject(AudioSource audio, bool showGui)
{
audio.Play();
2026-07-28 01:06:41 -04:00
if (showGui)
{
2026-07-18 23:30:43 -04:00
// Activate your GUI here
2026-07-28 01:06:41 -04:00
}
else
{
2026-07-18 23:30:43 -04:00
yield return new WaitUntil(() => audio.time >= audio.clip.length);
2026-07-28 01:06:41 -04:00
fadeOut.ResetFader();
2026-07-18 23:30:43 -04:00
}
}
2026-07-28 01:06:41 -04:00
void CheckScore()
2026-07-18 23:30:43 -04:00
{
int currentScore = PlayerPrefs.GetInt("CurrentScore");
AudioSource audio = null;
bool showGui = false;
2026-07-28 01:06:41 -04:00
if (GameSetup.IsHighScore(currentScore))
{
2026-07-18 23:30:43 -04:00
audio = winSound;
showGui = true;
2026-07-28 01:06:41 -04:00
}
else
{
2026-07-18 23:30:43 -04:00
audio = loseSound;
}
StartCoroutine(PlayAudioThenActivateGameObject(audio, showGui));
}
}