How to use keyboard button to skip the videoplayer to next clip?
I want to create a video player in unity which contents several video clips. I wish that I could manage the clips in the inspector like drag the clips into the box in the inspector. The video will automatically play the next clips when the previous one finished or when I press a certain key on the keyboard. I write below code to create the clipindex but when I run the video, it won't go to the next one under any circumstance. Could someone help a little bit at this script? Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class ClipManager : MonoBehaviour {
public VideoPlayer videoPlayer;
public VideoClip[] videoClip;
private int ClipIndex;
void Start () {
videoPlayer.clip = videoClip[0];
}
void Update () {
if (Input.GetKeyDown(KeyCode.N))
{
ClipIndex++;
videoPlayer.clip = videoClip[ClipIndex];
videoPlayer.Play();
}
}
}
Comment
Good day.
First, you must disconer what is not working. Is detecting the key? Is invreasing the int variable?
You can try to stop the video before change the clip.
Do you get any error?
As you see, you are not giving enough info. Debug your code!!
Bye!