标签:one exist object gas mat src collect err return
(1)首先需要添加组件“VideoPlayer”
source为视频来源,URL为视频路径。
(2)通过脚本控制视频播放,在Quad上挂载
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; using VRTK; using System.IO; public class GameItem : MonoBehaviour { public int Index; private VideoPlayer m_VideoPlayer; private void Awake() { m_VideoPlayer = GetComponent<VideoPlayer>(); GameObject.Find("ControllerRight").GetComponent<VRTK_ControllerEvents>().TouchpadReleased += GameItem_TouchpadReleased; GameObject.Find("ControllerLeft").GetComponent<VRTK_ControllerEvents>().TouchpadReleased += GameItem_TouchpadReleased; } private void Update() { if (Index == GameItemSelect._Instance.Index) { GetComponent<MeshCollider>().enabled = true; GetComponent<MeshRenderer>().material.color = Color.white; }else { GetComponent<MeshCollider>().enabled = false; GetComponent<MeshRenderer>().material.color = Color.gray; } } /// <summary> /// 圆盘按钮抬起 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameItem_TouchpadReleased(object sender, ControllerInteractionEventArgs e) { m_VideoPlayer.Pause(); } /// <summary> /// 设置视频名称 /// </summary> /// <param name="videoName"></param> public void SetVideoName(string videoName) { m_VideoPlayer.url = GetVideoPath(videoName); } /// <summary> /// 获取视频路径 /// </summary> /// <param name="videoName"></param> /// <returns></returns> private string GetVideoPath(string videoName) { return Application.dataPath + "/StreamingAssets/" + videoName + ".mp4"; } private void OnTriggerEnter(Collider other) { if (File.Exists(m_VideoPlayer.url) == false) return; m_VideoPlayer.Play(); } private void OnTriggerExit(Collider other) { m_VideoPlayer.Pause(); } }
标签:one exist object gas mat src collect err return
原文地址:https://www.cnblogs.com/dream-seeker-201907/p/11434329.html