using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; // To alter video using UnityEngine.UI; // For general image + button jobs using TMPro; // For text public class StartPause : MonoBehaviour { public VideoPlayer player; public Button button; public Sprite pauseSprite; public Image word_image; public TextMeshProUGUI title; public CourseList courselist; private Course course; private int word_i = 0; // In my example, i have 4 videos/images private int max_words = 4; // Start is called before the first frame update public void Awake() { course = courselist.courses[CourseIndex.index]; button.image.sprite = pauseSprite; title.text = course.name; next_video(); next_image(); } // These two functions generate video and image from files private void next_video(){ player.clip = course.videos[word_i]; // This loads first frame, so that it can be used as a sort-of preview for the video player.Play(); player.Pause(); // As the video will start paused -> show button Color col = button.image.color; col.a = 255; button.image.color = col; } // This doesn't work private void next_image(){ Sprite tex = course.images[word_i]; word_image.sprite = tex; } // Activate by pressing the center of the screen public void Pause() { if (!player.isPlaying) { // Play video and hide button player.Play(); Color col = button.image.color; col.a = 0; button.image.color = col; } else { // Pause video and show button player.Pause(); Color col = button.image.color; col.a = 255; button.image.color = col; } } // Press next-sign button for next word public void NextSign(){ word_i++; word_i %= max_words; next_video(); next_image(); } }