1.创建如下所示unity界面 button1:上一个视频 button2:播放/暂停 button3:下一个视频 vidotime:是一个text,显示视频时间 videoname:视频名称
2.具体界面如下所示
二、导入脚本1.在RawImage中导入脚本,实现对视频播放/暂停,及切换视频功能
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using UnityEngine.Video;public class Video_Controller : MonoBehaviour{ private VideoPlayer videoplayer; private RawImage rawImage; private int currentClipIndex; public Text text_playorpause; public Button button_playorpause; public Button button_pre; public Button button_next; public VideoClip[] videoClips; void Start() { videoplayer = this.GetComponent(); rawImage = this.GetComponent(); currentClipIndex = 0; button_playorpause.onClick.AddListener(OnplayorpauseVideo); button_pre.onClick.AddListener(OnpreVideo); button_next.onClick.AddListener(OnnextVideo); } // Update is called once per frame void Update() { if (videoplayer.texture == null) { return; } rawImage.texture = videoplayer.texture; } private void OnplayorpauseVideo() { if (videoplayer.enabled == true) { if (videoplayer.isPlaying) { videoplayer.Pause(); text_playorpause.text = "播放"; } else if (!videoplayer.isPlaying) { videoplayer.Play(); text_playorpause.text = "暂停"; } } } private void OnpreVideo() { currentClipIndex -= 1; if (currentClipIndex