How do you make a scene load after a movie played?

I need an answer ASAP! So, I have this script and it makes it play my movie, and I don’t know how to make it open a scene after the movie! The movie is 15 seconds long, and here is the script:

using UnityEngine;
using System.Collections;

public class VideoController : MonoBehaviour {

    // Use this for initialization
    void Start () {
 
        MovieTexture Movie = renderer.material.mainTexture as MovieTexture;
        Movie.Play ();


    }
 
    // Update is called once per frame
    void Update () {
 
    }
}

So, please respond as soon as possible! I need an answer fast!

A very simple way would be to use Invoke to call a function that loads the scene after the movie.

void Start()
{
      // same as your Start method, but with the following addition
      Invoke("LoadScene", Movie.duration + 0.1f);    // calls the method 0.1 seconds AFTER the movie has finished.
}

void LoadScene()
{
        Application.LoadLevel("sceneName");
}

Parsing error…

Okay, if there’s a parsing error in that section, I suspect it’s the second parameter of the Invoke statement. If that’s the case, give this a try.

void Start()
{
    // declare the MovieTexture here
    float duration = Movie.duration;
    Invoke("LoadScene", (duration + 0.1f) );
    // play the movie
}

Strange! It still gave a parsing error!

EDIT: I’ve had a look at the scripting reference, and it turns out that MovieTexture.duration is only available once the movie starts playing - before that, it returns -1. That means the code I gave you is calling Invoke with a negative number! :sweat_smile:

So, either try putting the Invoke call after you instruct the movie to play, or take note of how long it is and then hard-code that in.

Okay, the movie is exactly 15 seconds long, and it plays… What do I add in? The invoke is something I never heard of.

(Sorry, I don’t know much coding)

The Invoke method is one way to call a function after a time period, and is definitely the simplest way to do so. In this case, your Start method would probably be as follows:

void Start()
{
   MovieTexture Movie = renderer.material.mainTexture as MovieTexture;        
   Movie.Play ();
   Invoke("LoadScene", 15f);    // this will call the LoadScene method in 15 seconds
}

Hope that sorts it out.

Still isn’t loading, but there are definitely no errors…

What is happening that it is saying that the invoke cannot be called.

That’s progress, if it’s not throwing any compiler errors! :wink:

Application.LoadLevel uses either the index/number or the name of the level. In my original reply, I put levelName in quotes; so if you replace ‘levelName’ with the actual name of your level, it should work.

Yep, I tried that, and it still didn’t work, I double checked to see the duration of the video, and it appeared to be 10 seconds, so I changed the script and it still doesn’t work…

Okay…could you post your entire code?

Yes, here is the error…

Trying to Invoke method: VideoController.Menu couldn’t be called.

(I will post a seperate post for the complete script)

using UnityEngine;
using System.Collections;

public class VideoController : MonoBehaviour {

    // Use this for initialization
    void Start () {
   
        MovieTexture Movie = renderer.material.mainTexture as MovieTexture;
        Movie.Play ();
        Invoke("Menu", 10f);    // this will call the LoadScene method in 15 seconds

    }
   
    // Update is called once per frame
    void Update () {
   
    }
}

Oh, I see what you meant. In order to Invoke a method, the method has to exist in the first place. Your script doesn’t have a method called “Menu”, so Invoke fails. What you need to do here is to add it:

// leave your Start loop as it is

void Menu()
{
    // this will load a level named "myLevel"
    Application.LoadLevel("myLevel");     
}