我試圖通過網址加載視頻,但我不斷收到相同的錯誤。我使用的是Unity 5.3以及http://docs.unity3d.com/ScriptReference/WWW-movie.html的示例代碼(因爲當前示例未編譯而進行了大量修改)。無法通過WWW加載電影
using UnityEngine;
using System.Collections;
// Make sure we have gui texture and audio source
[RequireComponent (typeof(GUITexture))]
[RequireComponent (typeof(AudioSource))]
public class TestMovie : MonoBehaviour {
string url = "http://www.unity3d.com/webplayers/Movie/sample.ogg";
WWW www;
void Start() {
// Start download
www = new WWW(url);
StartCoroutine(PlayMovie());
}
IEnumerator PlayMovie(){
MovieTexture movieTexture = www.movie;
// Make sure the movie is ready to start before we start playing
while (!movieTexture.isReadyToPlay){
yield return 0;
}
GUITexture gt = gameObject.GetComponent<GUITexture>();
// Initialize gui texture to be 1:1 resolution centered on screen
gt.texture = movieTexture;
transform.localScale = Vector3.zero;
transform.position = new Vector3 (0.5f,0.5f,0f);
// gt.pixelInset.xMin = -movieTexture.width/2;
// gt.pixelInset.xMax = movieTexture.width/2;
// gt.pixelInset.yMin = -movieTexture.height/2;
// gt.pixelInset.yMax = movieTexture.height/2;
// Assign clip to audio source
// Sync playback with audio
AudioSource aud = gameObject.GetComponent<AudioSource>();
aud.clip = movieTexture.audioClip;
// Play both movie & sound
movieTexture.Play();
aud.Play();
}
}
我說這是一個腳本,在新場景中的主攝像頭,和我得到這個錯誤:
Error: Cannot create FMOD::Sound instance for resource (null), (An invalid parameter was passed to this function.)
UnityEngine.WWW:get_movie()
<PlayMovie>c__Iterator4:MoveNext() (at Assets/TestMovie.cs:20)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
TestMovie:Start() (at Assets/TestMovie.cs:16)
(第20行是MovieTexture movieTexture = www.movie;
) 我一直工作在本作現在,它發生在很多文件和我的兩個系統上。
我已經能夠使用Unity 5.2和5.1播放視頻。這是這個問題的最新版本。 – Alex
您是否試圖稍等一會?我不知道爲什麼現在出現這個錯誤,可能是Unity bug,但是看起來它不會停止函數執行。如果再等一會兒,電影將正常啓動,並且沒有聲音問題(確保'pixelInset'設置爲屏幕的某個可見部分)。 –
對我來說,它確實停止執行。當它工作在以前的版本時,我有音頻和調整設置以查看視頻。 – Alex