Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Cambio de escena al terminar video

Iniciado por brok, Febrero 07, 2018, 05:34:26 PM

Tema anterior - Siguiente tema
Hola a todos, miren tengo un problema quiero cargar una escena después de que termine un video y el video ya que va por url en un host y tengo este script pero no funciona, aver un poco de ayuda por favor.
 

using UnityEngine;
using UnityEngine.Video;
public class MovieLogo : MonoBehaviour {
void Start ()
    {
        GameObject camera = GameObject.Find("Main Camera");
        VideoPlayer videoPlayer = camera.AddComponent<VideoPlayer>();
        videoPlayer.playOnAwake = true;
        videoPlayer.renderMode = VideoRenderMode.CameraFarPlane;
        videoPlayer.url = "http://localhost/video/keansoft.mp4";
        for (int i = 0; i < videoPlayer.frameRate; i++)
        {
            if (videoPlayer.frameRate == 250)
            {
                UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Menu");
            }
        }
       
    }

}

 
 

Uffff, es lo que pasa por no buscar en la documentacion de Unity, el frameRate son los frames por segundo del video, y no entiendo que hace ese bucle por ahi, y menos en la funcion Start.
 
Prueba algo un poco mas metodico como esto, que tampoco te aseguro que funcione porque ni siquiera lo he probado, pero seguro que se acerca mas a lo que quieres conseguir.
 

using UnityEngine;
using UnityEngine.Video;
 
public class MovieLogo : MonoBehaviour{
    VideoPlayer vPlayer;
    GameObject camara;
    void Start()
    {
         camara = GameObject.Find("Main camera"); // esto bien
         vPlayer = camara.AddComponent<VideoPlayer>(); // esto bien
         vPlayer.source = VideoSource.Url; //debes indicarle la fuente de donde recoge el archivo si es una url
         vPlayer.renderMode = VideoRenderMode.CameraFarPlane; // esto bien
         vPlayer.url = "http://localhost/video/keansoft.mp4"; // esto bien
         vPlayer.Prepare(); //prepara el video, ya que tiene que cargarlo desde una url
         //el playOnAwake lo reproduce desde la funcion Awake que se ejecuta antes del Start, entonces Awake ya ha ocurrido
         vPlayer.loopPointReached += EndReached; //determina que manejador usa cuando finalice el video
    }
   
    void Update()
    {
        if(vPlayer.isPrepared && !vPlayer.isPlaying){ // esta preparado y sin reproducir???
            vPlayer.Play();// pues dale al play
        }
    }
    void EndReached(VideoPlayer vPlayer) //manejador que se ejecuta al terminar el video
    {
        UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Menu"); //vete al menu majo
    }
}

 
Espero que te sirva la ayuda ;)

Gracias me ha servido de mucho ya me funciona mil gracias chaskarron

Perfecto!!!! Si has necesitado modificar el codigo, ponlo para que sirva de ayuda a alguien que le surja la misma incidencia.
 
Saludos!!!


using UnityEngine;
using UnityEngine.Video;
 
public class MovieLogo : MonoBehaviour
{
    void Start()
    {
       
       GameObject camara = GameObject.Find("Main Camera");
       VideoPlayer vPlayer = camara.GetComponent<VideoPlayer>();
       vPlayer.source = VideoSource.Url;
       vPlayer.renderMode = VideoRenderMode.CameraFarPlane;
       vPlayer.url = "http://keansoft.es/votg/splashlooproad.mp4";
       vPlayer.Prepare();
       vPlayer.Play();                  
       vPlayer.loopPointReached += EndReached;
    }
 
void EndReached(VideoPlayer vPlayer)
{
      UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Menu");
}
 

 
Aquí esta a si me funciono a mi.

Etiquetas: