Search Unity

WWW Video with control buttons

Discussion in 'Scripting' started by DIGIMED, Oct 31, 2012.

  1. DIGIMED

    DIGIMED

    Joined:
    Oct 26, 2012
    Posts:
    21
    Hi everyone!

    I should say, this place is wonderfull... My past two threads were quickly responded and solved!
    Here is another one... I try to add some control buttons to Justin Warner's script I found @

    Well this is my 1st week to get play with javascript but believe or not, button placements worked just in one session :)
    But the interaction :(

    Actually this issue is the first step again. When this script bellow solved, I would like to put several videos to my scene that will be trigred via some buttons. But in this case, just changing the url would be enough... Anyway, here is the code and here is the package I exported, I think it would be easier to test for you...

    Thaks to possible responds...

    Code (csharp):
    1.  
    2. //video source
    3. var url = "http://www.digimed.com.tr/fuarassets/video/ardex.ogg";
    4.  
    5. //all items invisible
    6.  
    7. private var btoynat = false;
    8. private var btdurdur = false;
    9. private var btgeri = false;
    10. private var btbekle = false;
    11. private var btkapat = false;
    12.  
    13. //styles
    14. var bt0 : GUIStyle;
    15. var bt1 : GUIStyle;
    16. var bt2 : GUIStyle;
    17. var bt3 : GUIStyle;
    18. var bt4 : GUIStyle;
    19. var bt5 : GUIStyle;
    20.  
    21.  
    22. // ************************ not working :( *****************************
    23. function OnGUI(){
    24.     GUI.depth = 2; // refer line 78
    25.     //load video background image
    26.     if(GUI.Button(Rect(0,0,960,620), "",bt0)){
    27.             //do nothing, just load it...
    28.        
    29.     }
    30.    
    31.    
    32.     if(GUI.Button(Rect(452,453,58,58),"",bt1)){
    33.     if (renderer.material.movieTexture.isPlaying) {
    34.         renderer.material.movieTexture.Pause();
    35.         renderer.material.movieTexture.audioClip.Pause();
    36.         //change pause button 2 play button
    37.         GUI.Button(Rect(452,453,58,58), "",bt2);
    38.        
    39.             }
    40.        
    41.         else {
    42.             renderer.material.mainTexture.Play();
    43.             renderer.material.movieTexture.audioClip.Play();
    44.             //change play button 2 pause button
    45.         GUI.Button(Rect(452,453,58,58), "",bt1);
    46.         }
    47.    
    48.     }
    49.    
    50.     if(GUI.Button(Rect(513,466,28,28), "",bt3)){
    51.             //stop video  audio
    52.         renderer.material.movieTexture.Stop();
    53.         renderer.material.movieTexture.audioClip.Stop();
    54.     }
    55.    
    56.     if(GUI.Button(Rect(420,466,28,28), "",bt4)){
    57.             //rew video  audio actually stop...
    58.         renderer.material.movieTexture.Stop();
    59.         renderer.material.movieTexture.audioClip.Stop();
    60.     }
    61.    
    62.     if(GUI.Button(Rect(721,149,29,29), "",bt5)){
    63.             //stop video  close everything
    64.         renderer.material.movieTexture.Stop();
    65.         renderer.material.movieTexture.audioClip.Stop();
    66.         vidbg = false;
    67.         btoynat = false;
    68.         btdurdur = false;
    69.         btgeri = false;
    70.         btbekle = false;
    71.         btkapat = false;
    72.     }
    73.    
    74. }
    75.  
    76.  
    77. //lets begin :)
    78. // ************************ working :) *****************************
    79. // ********* but it appears under the background image :( **********
    80.  
    81. function Start () {
    82.     // Start download
    83.     var www = new WWW(url);
    84.  
    85.     // Make sure the movie is ready to start before we start playing
    86.     var movieTexture = www.movie;
    87.     while (!movieTexture.isReadyToPlay)
    88.         yield;     
    89.  
    90.     // Initialize gui texture to be 1:1 resolution centered on screen
    91.     guiTexture.texture = movieTexture;
    92.     GUI.depth = 1; // refer line 78
    93.     transform.localScale = Vector3 (0.15,-0.02,0);
    94.     transform.position = Vector3 (0.5,0.5,0);
    95.     guiTexture.pixelInset.xMin = -movieTexture.width / 2;
    96.     guiTexture.pixelInset.xMax = movieTexture.width / 2;
    97.     guiTexture.pixelInset.yMin = -movieTexture.height / 2;
    98.     guiTexture.pixelInset.yMax = movieTexture.height / 2;
    99.  
    100.     // Assign clip to audio source
    101.     // Sync playback with audio
    102.     audio.clip = movieTexture.audioClip;
    103.  
    104.     // Play both movie  sound
    105.     audio.Play();
    106.     movieTexture.Play();
    107.    
    108.     // I think this true false stuff is also not working...
    109.     btoynat = true;
    110.     btdurdur = true;
    111.     btgeri = true;
    112.     btileri = true;
    113.     btkapat =true;
    114. }
    115. // Make sure we have gui texture and audio source
    116. @script RequireComponent (GUITexture)
    117. @script RequireComponent (AudioSource)
    118.