Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I’ve two scenes: Opening Scene and Sport Scene.

The logic is to play the Opening Scene after which fade out then when the Sport Scene has loaded to fade in when the Sport Scene is already loaded.

the issue is that after doing the fadeout it is exhibiting empty scene it is like doing fade in or altering the alpha coloration of the canvas group and exhibiting empty scene then after a second or two loading the second scene.

however the fade out/in ought to be making the graceful transition between the scenes.

the canvasgroupfader script is connected to the canvas within the Opening Scene and the VideoManager script is connected to empty gameobject additionally within the Opening Scene.

that is the canvas group fade script:

utilizing UnityEngine;

public class CanvasGroupFader : MonoBehaviour
{
    public float fadeDuration = 1.0f; // Period of the fade in seconds
    personal CanvasGroup canvasGroup;

    personal float targetAlpha;
    personal float startAlpha;
    personal float startTime;

    personal bool isFading;

    personal void Begin()
    {
        canvasGroup = GetComponent<CanvasGroup>();
    }

    personal void Replace()
    {
        if (isFading)
        {
            float elapsedTime = Time.time - startTime;
            float t = Mathf.Clamp01(elapsedTime / fadeDuration);

            float newAlpha = Mathf.Lerp(startAlpha, targetAlpha, t);
            canvasGroup.alpha = newAlpha;

            if (t >= 1.0f)
            {
                isFading = false;
            }
        }
    }

    public void StartFade(float startAlphaValue, float targetAlphaValue)
    {
        if (!isFading)
        {
            startAlpha = startAlphaValue;
            targetAlpha = targetAlphaValue;
            startTime = Time.time;

            isFading = true;
        }
    }

    // Public strategies to provoke fading
    public void FadeIn()
    {
        StartFade(0f, 1f);
    }

    public void FadeOut()
    {
        StartFade(1f, 0f);
    }
}

and that is how I am utilizing it:

utilizing UnityEngine;
utilizing UnityEngine.EventSystems;
utilizing UnityEngine.Video;
utilizing UnityEngine.UI;
utilizing TMPro;
utilizing System.Collections;
utilizing UnityEngine.SceneManagement;

public class VideoManager : MonoBehaviour, IDragHandler, IPointerDownHandler
{
    public VideoPlayer participant;
    public Picture progress;
    public TextMeshProUGUI videoFileName;
    public float scrollSpeed = 50f;
    public CanvasGroupFader canvasGroupFader;

    personal bool isVideoFinished = false;

    personal void Begin()
    {
        participant.prepareCompleted += Player_prepareCompleted;
        participant.loopPointReached += Player_loopPointReached;
        videoFileName.textual content = participant.clip.title;
    }

    personal void Player_prepareCompleted(VideoPlayer supply)
    {
        isVideoFinished = false;
    }

    personal void Player_loopPointReached(VideoPlayer supply)
    {
        VideoFinished(supply);
    }

    void Replace()
    {
        if (participant.frameCount > 0 && isVideoFinished == false)
        {
            progress.fillAmount = (float)participant.body / (float)participant.frameCount;
        }

        if (!isVideoFinished && participant.isPlaying && (ulong)participant.body >= participant.frameCount - 1)
        {
            VideoFinished(participant);
        }
    }

    public void OnDrag(PointerEventData eventData)
    {
        TrySkip(eventData);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        TrySkip(eventData);
    }

    personal void SkipToPercent(float pct)
    {
        var body = participant.frameCount * pct;
        participant.body = (lengthy)body;
    }

    personal void TrySkip(PointerEventData eventData)
    {
        Vector2 localPoint;
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(
            progress.rectTransform, eventData.place, null, out localPoint))
        {
            float pct = Mathf.InverseLerp(progress.rectTransform.rect.xMin, progress.rectTransform.rect.xMax, localPoint.x);
            SkipToPercent(pct);
        }
    }

    public void VideoPlayerPause()
    {
        if (participant != null)
            participant.Pause();
    }

    public void VideoPlayerPlay()
    {
        if (participant != null)
            participant.Play();
    }

    personal void VideoFinished(VideoPlayer supply)
    {
        isVideoFinished = true;
        progress.fillAmount = 1f;

        canvasGroupFader.FadeOut(); // Begin fade-out impact
        StartCoroutine(LoadSceneAfterFade()); // Begin loading the brand new scene after the fade-out
    }

    personal IEnumerator LoadSceneAfterFade()
    {
        // Anticipate the fade-out impact to finish
        yield return new WaitForSeconds(canvasGroupFader.fadeDuration);

        // Load the brand new scene asynchronously
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);

        // Wait till the brand new scene is absolutely loaded
        whereas (!asyncLoad.isDone)
        {
            yield return null;
        }

        // Begin the fade-in impact after the brand new scene is loaded
        canvasGroupFader.FadeIn();
    }

    personal void OnDestroy()
    {
        participant.prepareCompleted -= Player_prepareCompleted;
        participant.loopPointReached -= Player_loopPointReached;
    }
}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *