Advertisement
dronkowitz

CGTheater.cs

Jul 27th, 2021 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.Video;
  6.  
  7. public class CGTheater : MonoBehaviour
  8. {
  9.     public static string currentvid;
  10.     public static string nextscene;
  11.     public List<VideoClip> Videos = new List<VideoClip>();
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.        
  16.         StartCoroutine(PlayVideo());
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.  
  23.    
  24.  
  25. }
  26.     public IEnumerator PlayVideo()
  27.     {
  28.        
  29.         foreach (VideoClip v in Videos)
  30.         {
  31.             if (v.name == currentvid)
  32.             {
  33.                 GetComponent<VideoPlayer>().clip = v;
  34.             }
  35.         }
  36.         GetComponent<VideoPlayer>().Play();
  37.         //the video may be running in 30 Frames per second. So if a video is 10 seconds long the frame count will be 300.
  38.         //if the computer is running at 60 fps, than the video would end half way through because the computer counted to 300 in half the time
  39.         VideoPlayer vp = GetComponent<VideoPlayer>();
  40.         string i = GetComponent<VideoPlayer>().frameCount.ToString();
  41.         int frames = int.Parse(i);
  42.        
  43.  
  44.            
  45.  
  46.         float currenttime = 0;
  47.         float finaltime = ((float)vp.length);
  48.  
  49.         while (currenttime < finaltime)
  50.         {
  51.             yield return new WaitForSeconds(Time.deltaTime);
  52.             currenttime += Time.deltaTime;
  53.             if (Input.GetKeyDown(KeyCode.Escape))
  54.             {
  55.                 break;
  56.             }
  57.         }
  58.  
  59.  
  60.  
  61.         SceneManager.LoadScene("CG Theater");
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement