I. Introduction▲
Cette série explique comment jouer une vidéo dans une scène Unity.
Vous pouvez retrouver les autres épisodes de cette série dans le sommaire dédié.
II. Vidéo▲
Unity - Jouer une vidéo
III. Résumé▲
Dans cette vidéo, vous allez apprendre comment passer d'une vidéo à une autre. Pour cela, le script précédent est amélioré afin de pouvoir gérer plusieurs clips vidéo :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
public class WorldSpaceVideo : MonoBehaviour {
public Material playButtonMaterial;
public Material pauseButtonMaterial;
public Renderer playButtonRenderer;
public VideoClip[] videoClips;
private VideoPlayer videoPlayer;
private int videoClipIndex;
void Awake()
{
videoPlayer = GetComponent<VideoPlayer> ();
}
// Use this for initialization
void Start ()
{
videoPlayer.clip = videoClips [0];
}
// Update is called once per frame
void Update ()
{
}
public void SetNextClip()
{
videoClipIndex++;
if (videoClipIndex >= videoClips.Length)
{
videoClipIndex = videoClipIndex % videoClips.Length;
}
videoPlayer.clip = videoClips [videoClipIndex];
videoPlayer.Play ();
}
public void PlayPause()
{
if (videoPlayer.isPlaying)
{
videoPlayer.Pause ();
playButtonRenderer.material = playButtonMaterial;
} else
{
videoPlayer.Play ();
SetTotalTimeUI ();
playButtonRenderer.material = pauseButtonMaterial;
}
}
}De plus, pour associer la nouvelle fonction « SetNextClip() » à un bouton, vous devez ajouter ce script au bouton approprié :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NextButtonControl : ShootableUI {
public override void ShotClick ()
{
worldSpaceVideo.SetNextClip ();
}
}IV. Ressources▲
Vous pouvez télécharger les ressources pour ce projet ici.
V. Commenter▲
Vous pouvez commenter et donner vos avis dans la discussion associée sur le forum.




