unity3d 在Sphere上播放视频

128 篇文章 1 订阅
64 篇文章 1 订阅

播放音频使用VideoPlayer组件。

首先搭建如下场景,场景中创建一个Sphere.

在Sphere上面添加VideoPlayer组件,并且给VideoClip赋值一个视频(MP4格式)。

给Sphere添加如下脚本:

  1.     public Button but1;
  2.     public Button but2;
  3.     public Button but3;
  4.    public VideoPlayer video;
  5.     void Start () {
  6.         but1 = GameObject.Find("Button1").GetComponent<Button>();
  7.         but1.onClick.AddListener(OnBut1);
  8.         but2 = GameObject.Find("Button2").GetComponent<Button>();
  9.         but2.onClick.AddListener(OnBut2);
  10.         but3 = GameObject.Find("Button3").GetComponent<Button>();
  11.         but3.onClick.AddListener(OnBut3);
  12.          video = gameObject.GetComponent<VideoPlayer>();
  13.     }
  14.     void OnBut1() {
  15.         if (!video.isPlaying)
  16.         {
  17.             video.Play();
  18.         }
  19.     }
  20.     void OnBut2() {
  21.         if (video.isPlaying)
  22.         {
  23.             video.Pause();
  24.         }
  25.     }
  26.     void OnBut3() {
  27.         if (video.isPlaying)
  28.         {
  29.             video.Stop();
  30.         }
  31.     }

 运行,小球上面就会播放视频,button可以控制视频的播放,暂停,关闭。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值