Unity学习之—视频播放问题

bug再现:

当把播放的视频拖拽到MovieTexture上,打包后 即使将这个视频删除了,程序仍可以播放视频。

movieTexture.Play(); 直接播放视频。经过群里大神指导发现,当你拖拽物体到对应的脚本时候unity自己会关联资源关系,从而直接打包到项目中。

www动态加载播放视频代码:

using UnityEngine;
using System.Collections;
 
public class MovePlay : MonoBehaviour {
 
    public MovieTexture movieTexture;
        public WWW www;
    string datapath;
 
	// Use this for initialization 
	void Start () { 
        datapath = Application.streamingAssetsPath+ "/DLXX.ogv";
        Debug.Log("file://" + datapath  );
        StartCoroutine(OnLoadMove());
    }
	
	// Update is called once per frame
	void Update () {
	
	}
    void OnGUI() {
        if (GUILayout.Button("play")) {
            movieTexture.Play();
        }
 
    }
    IEnumerator OnLoadMove() {
        www = new WWW("file://"+datapath);
        Debug.Log(www);
        yield return www;
        movieTexture = www.movie;
        renderer.material.mainTexture = movieTexture;
        movieTexture.loop = true;
       // movieTexture.Play();
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章