Page 1 sur 1

Unity3d simple www VideoPlayer (Stop OnTriggerOut)

Publié : mar. avr. 19, 2011 3:28 am
par yann.minh
Script Written by Eric Wenger for the Noomuseum of Yann Minh, in April 2010

Lecteur video simple, sans boutons , avec detection de collision pour stoper la lecture.

Script a mettre dans l'ecran

Code : Tout sélectionner

var url = "http://www.yannminh.org/ShortFilms/NooGenesis-512.ogg";  // Lien de la video
public var object:GameObject; // Objet sur lequel doit être afficher la video
private var isplaying=false;
private var iswaiting=false;
var www : WWW;
var m : MovieTexture;

function Start () {
    www = new WWW(url);
    m= www.movie;
   // m  = object.renderer.material.mainTexture as MovieTexture;
    object.renderer.material.mainTexture= m; 
   audio.clip = m.audioClip;
}
//------------//
function MovieController( action ) { 
switch(action){
case 0:    m.Stop(); audio.Stop();   isplaying=false;   break;
case 1:          
            while (!m.isReadyToPlay) yield; 
             iswaiting=false;
            m.Play(); 
            audio.Play();   
            isplaying=true;   
            
            break;
case 2:    m.Pause(); audio.Pause();   isplaying=false;   break;
}
}

//------------//

function Update () {
   if(isplaying){   //do something while playing
      renderer.material.color =Color.white; 
   }else{
      if(iswaiting) renderer.material.color =Color.green;     
   }
}

function OnMouseDown () { 
    
   audio.clip = m.audioClip;
   if(isplaying==true){
      MovieController( 2 );
   }else{
      iswaiting=true;
      MovieController( 1 );
   }
}


@script RequireComponent (AudioSource)

Script a mettre dans le collider

Code : Tout sélectionner

var Target : GameObject;

function Update(){
    
}

function OnTriggerEnter (other : Collider) { 
   var script : videocontroller;
    script=  Target.GetComponent("videocontroller");
    // Call the function DoSomething on the script
     script.MovieController(1); //play
}

function OnTriggerExit (other : Collider) { 
   
   var script : videocontroller;
    script= Target.GetComponent("videocontroller");
    // Call the function DoSomething on the script
     script.MovieController(0); //stop
}