#Fading Help.

1 messages · Page 1 of 1 (latest)

fresh cloud
#

Hi! I'm trying to make this fading thing work, but I just can't seem to make it work. I have got a game menu scene and a opening scene. When I start the opening scene on it's own then the fade in works perfectly. When I try to start the scene by pressing my "START GAME" button then the opening scene doesn't have a fade.

ancient fractal
#

post code
!code

wise skyBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

fresh cloud
#
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;


public class FadeController : MonoBehaviour
{
    public RawImage fadeImage;
    public float fadeDuration = 1f;

    private void Start()
    {
        FadeIn();
    }

    public void FadeOut()
    {
        StartCoroutine(FadeOutCoroutine());
    }

    private IEnumerator FadeOutCoroutine()
    {
        float elapsedTime = 0f;
        while (elapsedTime < fadeDuration)
        {
            float alpha = Mathf.Lerp(0f, 1f, elapsedTime / fadeDuration);
            fadeImage.color = new Color(0f, 0f, 0f, alpha);
            elapsedTime += Time.deltaTime;
            yield return null;
        }
        fadeImage.color = new Color(0f, 0f, 0f, 1f);

        LoadNextScene();
    }

    public void FadeIn()
    {
        StartCoroutine(FadeInCoroutine());
    }

    private IEnumerator FadeInCoroutine()
    {
        float elapsedTime = 0f;
        while (elapsedTime < fadeDuration)
        {
            float alpha = Mathf.Lerp(1f, 0f, elapsedTime / fadeDuration);
            fadeImage.color = new Color(0f, 0f, 0f, alpha);
            elapsedTime += Time.deltaTime;
            yield return null;
        }
        fadeImage.color = new Color(0f, 0f, 0f, 0f);
    }

    public void LoadNextScene()
    {
        SceneManager.LoadScene("Opening_Scene2"); // Replace "Opening_Scene2" with the name of your next scene
    }
}
#

this is the code for my Opening Scene

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public Animator fadeAnimator;
    public float fadeDuration = 1f;

    public void HandleStartGameClick()
    {
        StartCoroutine(StartGameRoutine());
    }

    private IEnumerator StartGameRoutine()
    {
        fadeAnimator.gameObject.SetActive(true);
        fadeAnimator.Play("FadeOut");

        yield return new WaitForSeconds(fadeDuration);

        SceneManager.LoadScene("Opening_Scene"); // Replace "Opening_Scene" with the name of your opening scene
    }

    public void HandleQuitGameClick()
    {
        StartCoroutine(QuitGameRoutine());
    }

    private IEnumerator QuitGameRoutine()
    {
        fadeAnimator.gameObject.SetActive(true);
        fadeAnimator.Play("FadeOut");

        yield return new WaitForSeconds(fadeDuration);

        Application.Quit();
    }
}

this is the code I use in my game menu scene, a different fading type

#

but the second scene shouldn't even interact with the game menu scene, but it just isn't starting the fade in when I press start the game from my game menu.