Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you hide a UI object (Video Player) after time?

I am very new to using Unity and I am surviving off tutorials from YouTube. As soon as my game is launched, a video is started using Video Player. I am hoping to make the video hidden after the video has finished playing to reveal my menu screen. I do have a script that I have used to hide the video player

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HideVideo : MonoBehaviour
{

public GameObject VideoPlayer;
public void HideVideoPlayer()
{
    VideoPlayer.gameObject.SetActive(false);
}
}

The problem is, the closest I have gotten to actually hiding my video is by setting it to an onclick event via a button. How do I make the video player hide after the video is finished playing? Thanks.

like image 895
Sui Avatar asked Dec 06 '25 18:12

Sui


1 Answers

using UnityEngine;
using UnityEngine.Video;

public class intro : MonoBehaviour
{
    public VideoPlayer videoPlayer;
    private bool isPlayerStarted = false;

    void Update()
    {
        if (!isPlayerStarted && videoPlayer.isPlaying)
        {
            isPlayerStarted = true;
        }

        if (isPlayerStarted && !videoPlayer.isPlaying)
        {
            videoPlayer.gameObject.SetActive(false);
            isPlayerStarted = false;
        }
    }
}
like image 66
Christian Müller Avatar answered Dec 09 '25 19:12

Christian Müller