Detecting when a video finished playing

Hello there! I need some help, referring to a question I have already asked ( Creating a Game Over after a Trigger/Event - Questions & Answers - Unity Discussions ).
So, I am trying to change my scene after a video is playing, but the problem now is that I am not sure how to make my game understand that the video has finished.

So, I have a trigger collider. When I enter this trigger, my video starts playing.
Attached, here, the script:

     public GameObject videoPlayer;
     public int timeToStop;
 
     // Use this for initialization
     void Start()
     {
         videoPlayer.SetActive(false);
     }
 
     // Update is called once per frame
     void OnTriggerEnter(Collider player)
     {
 
         if (player.gameObject.tag == "Player")
         {
             videoPlayer.SetActive(true);
             Destroy(videoPlayer, timeToStop);
         }
     }
 }

This is the code I have attached to the trigger. That “time to stop” is a “delay time”, let’s call it like that, that I can set— that does what the name tells, sets a time to stop.
I would like to add a Game Over method WHEN the video stops playing, but I would like some suggestions on how to do that. I have seen some different methods, but I am not sure.

Also, I was thinking about detecting when the object gets destroyed, since there is a Destroy method? But, still, I would really appreciate some suggestions for that. Thank you so much!!

Good day again!

I see you didnt made any research by your own… And you should… you will be obstructed every time if dont learn how to “solve new unexpected problems” like this.

As i said yesterday, i never used videos in unity, but with only 25 seconds, i find the solution… so you could at least tried…

As it says, yo umust wait a little once you do videoplayer.play(), before check if is still playing, because diring first moments is still preparing the video.

If you are lazy to read the API of Unity, you are lazy for developing a game…

Bye!

Hello everybody again! Since I have seen there have been LOADS of people following this question, I wanted to post another answer since I have found the correct method.
So, the main reason I never got the correct code, is because I was thinking “ehi, I am destroying the object, so maybe I can rely on that”. So, since I had

  public GameObject videoPlayer;

I was keeping and keeping putting a videoPlayer.activeInHierarchy == false or something.
The solution is easier than that!! Don’t rely on the fact you have your object destroyed, but consider a Coroutine.

My final code is:

public class VideoPlayerTimer : MonoBehaviour
{
    public GameObject videoPlayer;
    public int timeToStop;
    public bool activeInHierarchy;

    // Use this for initialization
    void Start()
    {
        videoPlayer.SetActive(false);
    }

    // Update is called once per frame
    void OnTriggerEnter(Collider player)
    {

        if (player.gameObject.tag == "Player")
        {
            StartCoroutine(CoFunc());
            videoPlayer.SetActive(true);
            Destroy(videoPlayer, timeToStop);
        }
    }


    IEnumerator CoFunc()
    {
        yield return new WaitForSeconds(14);
        SceneManager.LoadScene(0);
    }
}

Basically, I did the “most obvious thing”: you put a StartCoroutine function when your player hits the collider and the video starts. That method will call the IENumerator and literally will wait for some time before loading the new scene. Now, my video lasted 14 seconds and 14 seconds is actually the perfect amount of seconds I needed- maybe you have to change it, maybe you want to change the time to stop, still it works. After these seconds, it will bring you to the new scene (in my case in my Main Menu, level 0).

That’s it!! Sorry for all the troubles and sorry for putting another comment, I was just really confused and I had to change my point of view. Hope it helps somehow someone!

you can see it: Unity - Scripting API: VideoPlayer

This is old but if you stumbled upon this thread like I did this is what you’re looking for