用户登录
用户注册

分享至

unity视频播放

  • 作者: 别闹丶这是个认真的玩笑
  • 来源: 51数据库
  • 2020-09-23
其实就和你显示图片,音频什么的一样的道理。视频一般是面形式展现的
第一步:在场景中新建一个面(plane对象) GameObject ->create other -> plane
第二步:新建一个script脚本文件控制视频的播放(这里提供的是C#脚本 Script_moveTest.cs) 代码如下
using UnityEngine;
using System.Collections;

public class Script_moveTest: MonoBehaviour {

//电影纹理
public MovieTexture mov;
// Use this for initialization
void Start () {
//设置当前对象的纹理是电影纹理
renderer.material.mainTexture = mov;
//设置为循环播放
mov.loop = true;
}
void OnGUI()
{
if(GUILayout.Button("播放/继续播放")){
if(!mov.isPlaying){
mov.Play();
}
}

if(GUILayout.Button("暂停播放")){
mov.Pause();
}

if(GUILayout.Button("停止播放")){
mov.Stop();
}

}
}

第三步:将该脚本绑定到第一步中创建的plane对象上,并给脚本赋值你要播放的视频纹理。
你就可以运行了,(打这么久挺累的)望采纳!!谢谢



  public movietexture movtexture;
void start()
{
//电影纹理
renderer.material.maintexture = movtexture;
//设置电影纹理播放模式为循环
//movtexture.loop = true;
}

void ongui()
{
if(guilayout.button("播放/继续"))
{

if(!movtexture.isplaying)
{
movtexture.play();
}

}

if(guilayout.button("暂停播放"))
{
movtexture.pause();
}

if(guilayout.button("停止播放"))
{
movtexture.stop();
}
}
将需要播放的视频,拖入为“movtexture”的对象赋值
软件
前端设计
程序设计
Java相关