Hey all! I was trying to make a seamless video switcher in unity, while keeping the same audio track. However, whenever i switch videos using the C key, there’s like 5 frames between video and video that nothing appears, making the switch a bit choppy. I’m still a beginner but here’s my code. Thank you so much!
Any help or clue on that I can do? Sorry if the question seems a bit stupid!
using UnityEngine;
using UnityEngine.Video;
public class VideoSwitcher : MonoBehaviour
{
public VideoPlayer[] videoPlayers;
private int currentIndex = 0;
public AudioSource audioSource;
public AudioClip audioClip;
void Start()
{
audioSource.clip = audioClip;
audioSource.Play();
videoPlayers[currentIndex].Play();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
double currentTime = videoPlayers[currentIndex].time;
videoPlayers[currentIndex].Stop();
currentIndex++;
if (currentIndex >= videoPlayers.Length)
{
currentIndex = 0;
}
videoPlayers[currentIndex].time = currentTime;
videoPlayers[currentIndex].Play();
}
}
}