视频导入Unity,需要先安装QuickTime Player,不能识别视频,需要重启下电脑
转换视频格式,转换成mov格式,之前系统上可以播放mp4格式,现在的电脑mp4视频,播放出来是黑屏,不知是视频问题还是什么问题,转换成mov在播放,就好了
using UnityEngine; using System.Collections; public class MovieTest : MonoBehaviour { public MovieTexture movTexture; public AudioSource movAudio; void Start() { renderer.material.mainTexture = movTexture; movTexture.loop = true; } void OnGUI() { if (GUILayout.Button("播放/继续")) { if (!movTexture.isPlaying) { movTexture.Play(); movAudio.Play(); } } if (GUILayout.Button("暂停播放")) { movTexture.Pause(); movAudio.Pause(); } if (GUILayout.Button("停止播放")) { movTexture.Stop(); movAudio.Stop(); } } }
Material[] ms = GetComponent<Renderer>().materials; Material m = ms.FirstOrDefault(w => w.name.IndexOf("GGJ_1") != -1); if (m != null) { moveTexture = m.mainTexture as MovieTexture; moveTexture.loop = true; moveTexture.Play(); }