FadeToBlack, DayComplete
This commit is contained in:
parent
58a58c70c3
commit
8cf29eed5a
7 changed files with 3570 additions and 9 deletions
77
Assets/Scripts/FadeToBlack.cs
Normal file
77
Assets/Scripts/FadeToBlack.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FadeToBlack : MonoBehaviour
|
||||
{
|
||||
public float fadeDuration = 2f;
|
||||
private Image fadeImage;
|
||||
private bool startFading = false;
|
||||
private float timer = 0f;
|
||||
private bool fadeComplete = false;
|
||||
public GameObject startMenuUI; // Assign this in Inspector if needed
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
fadeImage = GetComponent<Image>();
|
||||
|
||||
if (fadeImage == null)
|
||||
{
|
||||
Debug.LogError("FadeToBlack: No Image component found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Color startColor = fadeImage.color;
|
||||
startColor.a = 0f;
|
||||
fadeImage.color = startColor;
|
||||
|
||||
Debug.Log("FadeToBlack: Initialized with alpha 0.");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (startFading && !fadeComplete)
|
||||
{
|
||||
timer += Time.unscaledDeltaTime;
|
||||
float alpha = Mathf.Clamp01(timer / fadeDuration);
|
||||
|
||||
Color newColor = fadeImage.color;
|
||||
newColor.a = alpha;
|
||||
fadeImage.color = newColor;
|
||||
|
||||
if (alpha >= 1f)
|
||||
{
|
||||
fadeComplete = true;
|
||||
Debug.Log("FadeToBlack: Fade complete.");
|
||||
OnFadeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartFade()
|
||||
{
|
||||
Debug.Log("FadeToBlack: StartFade() called.");
|
||||
startFading = true;
|
||||
|
||||
if (fadeImage != null)
|
||||
{
|
||||
fadeImage.color = new Color(0f, 0f, 0f, 0f); // Ensure it's black and invisible at the start
|
||||
}
|
||||
|
||||
if (startMenuUI != null && startMenuUI.activeInHierarchy)
|
||||
{
|
||||
Debug.Log("Start menu was still active — disabling it.");
|
||||
startMenuUI.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnFadeComplete()
|
||||
{
|
||||
Debug.Log("Fade complete — now locking cursor and pausing game.");
|
||||
Time.timeScale = 0f;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue