2014-09-02 86 views
0

我已經編寫了一個腳本來播放OGG文件作爲MovieTexture,我已經嘗試了嵌入式資產文件,也嘗試了從網絡。我遇到的問題是,該視頻在調試移動發揮(當我打的「遊戲」選項卡上的播放按鈕和測試),但是當我建立一個可執行的他們從來沒有工作..MovieTexture Never Plays In Build

using UnityEngine; 

namespace Assets.Scripts 
{ 
    [RequireComponent(typeof(AudioSource))] 
    public class VideoScreen : MonoBehaviour 
    { 
     public string videoUrl; 
     public bool autoPlay = true; 
     public bool loop = true; 
     public bool playAudio = true; 
     public float opacity = 1.0f; 

     private bool hasLoaded; 
     private MovieTexture movieTexture; 

     public void Start() 
     { 
      if (string.IsNullOrEmpty(videoUrl)) 
      { 
       return; 
      } 

      var data = new WWW(videoUrl); 
      movieTexture = data.movie as MovieTexture; 
     } 

     public void Update() 
     { 
      if (movieTexture.isReadyToPlay && !hasLoaded) 
      { 
       renderer.material = new Material(Shader.Find("Custom/Unlit Transparent Color")) { mainTexture = movieTexture }; 
       audio.clip = movieTexture.audioClip; 

       SetLoop(loop); 

       if (autoPlay) 
       { 
        Play(); 
       } 

       hasLoaded = true; 
      } 

      var textureColor = renderer.material.color; 
      textureColor.a = opacity; 
      renderer.material.color = textureColor; 
     } 

     private void Play() 
     { 
      movieTexture.Stop(); 
      movieTexture.Play(); 

      if (playAudio) 
      { 
       audio.Stop(); 
       audio.Play(); 
      } 
     } 

     private void Pause() 
     { 
      movieTexture.Pause(); 
      if (playAudio) 
      { 
       audio.Pause(); 
      } 
     } 

     private void Stop() 
     { 
      movieTexture.Stop(); 
      if (playAudio) 
      { 
       audio.Stop(); 
      } 
     } 

     private void SetLoop(bool loopStatus) 
     { 
      movieTexture.loop = loopStatus; 
      if (playAudio) 
      { 
       audio.loop = loopStatus; 
      } 
     } 
    } 
} 

燦任何人都會對此行爲有所瞭解?

謝謝

回答

0

變成我使用的自定義透明漫反射着色引起的問題!衛生署!

renderer.material = new Material(Shader.Find("Custom/Unlit Transparent Color")) { mainTexture = movieTexture }; 

現在變成

renderer.material.mainTexture = movieTexture;