gimm270_13_videoinunity/Assets/Scripts/VideoPlayerManager.cs

54 lines
1.8 KiB
C#

using UnityEngine.Video; //Must be using UnityEngine.Video
using UnityEngine;
public class VideoPlayerManager : MonoBehaviour
{
public VideoPlayer videoPlayer; //Our video player component variable. Can be set in inspector or through code in Start()
public VideoClip[] clips; //Array for video clips
// Start is called before the first frame update
void Start()
{
videoPlayer = GetComponent<VideoPlayer>(); //Stores our video player component into our videoPlayer variable
}
private void Update()
{
//Check to see if the current clip has ended. Once it's over, call to PlayClip()
if ((videoPlayer.frame) > 0 && (videoPlayer.isPlaying == false))
{
PlayClip();
}
}
public void PlayClip()
{
if (videoPlayer.clip == clips[0]) //Checks to see if the clip that just played was the first video
{
int randClip = Random.Range(1, 3); //Randomly picks one of the remaining three videos
videoPlayer.clip = clips[randClip]; //Sets the videoPlayer clip to the next chosen video
}
else if(videoPlayer.clip == clips[1] || videoPlayer.clip == clips[2] || videoPlayer.clip == clips[3])
{
videoPlayer.clip = clips[4]; // play the last clip
}
else if (videoPlayer.clip == clips[4]) //If we've just played the last clip, play a bit of blackness.
{
videoPlayer.clip = clips[5];
}
else
{
videoPlayer.clip = clips[0]; //If the last played video wasn't the first video, then go back to playing that first video
}
}
}