Unity2019_视频播放

 摄像机上挂个视频组件Video Player,选择视频文件类型,有视频片段,URL地址,指定视频文件,选择近摄像机平面,需要指定摄像机Camera

渲染器纹理模式

首先创建一个渲染器纹理,

纹理尺寸修改到和相机一致

 给摄像机指定纹理

创建一个原图

材质搞上

材质覆盖,类型广告牌,墙上的大屏幕播放视频

新建一个3D物体,例如plane,物体上需要带网格渲染器

修改模式,指定渲染器Plane

 同时添加一个方向光,照着Plane。

 音频模式,音频源,下面是音频源的设置,如果直接用视频中的声音,勾选直接就可以。

 常用函数

using UnityEngine;
using UnityEngine.Video;

public class VidioTest : MonoBehaviour
{
    VideoPlayer video;
    // Start is called before the first frame update
    void Start()
    {
        video = transform.GetComponent<VideoPlayer>();
        // 设置视频类型
        video.source = VideoSource.VideoClip;
        video.clip = Resources.Load<VideoClip>("GameExplain");
        video.source = VideoSource.Url;
        video.url = "视频网址";
    }

    // Update is called once per frame
    void Update()
    {
		if (Input.GetKeyDown("a"))
		{
			if (!video.isPlaying)
			{
                video.Play();
            }
		}
        if (Input.GetKeyDown("b"))
        {
            video.Pause();
        }
        if (Input.GetKeyDown("c"))
        {
            video.Stop();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_35647121/article/details/126822273