I am trying to create a series of video tutorial in game, at the start it will play the first video, the player can close the video by pressing the close button
then if the player level’s up and click okay, it supposed to trigger the 2nd video tutorial but it is not working and keep saying “Cannot Play a disabled VideoPlayer” even though it is enabled in the Hierarchy.
Here is the code:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class TutorialVideoManager : MonoBehaviour
{
[SerializeField] private VideoPlayer videoPlayer;
[SerializeField] private RawImage videoDisplay;
[SerializeField] private Button closeButton;
[SerializeField] private VideoClip[] tutorialVideos;
private int currentIndex = 1;
private void Start()
{
if (tutorialVideos.Length > 0)
{
Debug.Log("Starting the first tutorial video.");
PlayTutorialVideo(0); //play first video
closeButton.onClick.RemoveAllListeners();
closeButton.onClick.AddListener(CloseVideo);
}
else
{
Debug.LogError("No tutorial videos assigned in the tutorialVideos array.");
}
}
public void TriggerTutorial()
{
Debug.Log($"TriggerTutorial called at index {currentIndex}");
if (currentIndex < tutorialVideos.Length)
{
PlayTutorialVideo(currentIndex); //play 2nd video which is index = 1
currentIndex++; // increment for future videos
}
else
{
Debug.LogWarning("All tutorial videos have been played.");
}
}
public void PlayTutorialVideo(int index)
{
Debug.Log($"Video display active: {videoDisplay.gameObject.activeSelf}");
Debug.Log($"Play Tutorial called at index {index}");
videoDisplay.gameObject.SetActive(true);
closeButton.gameObject.SetActive(true);
videoPlayer.clip = tutorialVideos[index];
videoPlayer.enabled = true;
videoPlayer.Prepare();
videoPlayer.Play();
}
public void CloseVideo()
{
videoPlayer.Stop();
videoDisplay.gameObject.SetActive(false);
closeButton.gameObject.SetActive(false);
}
}
the TriggerTutorial() was called in this method in my levelup script
public void OnComplete()
{
gameObject.SetActive(false);
HUD.SetActive(true);
Debug.Log("Completed LevelUP");
VideoManager.TriggerTutorial();
}