Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Multiple video sources for different segments of a song

Discussion in 'Audio & Video' started by joacoerazo, Aug 1, 2020.

  1. joacoerazo

    joacoerazo

    Joined:
    Dec 6, 2014
    Posts:
    1
    Hi to all

    I have a song divided in 17 segments, each segment has 2 or 3 possible videos (I need to change them randomly in that segment). Any clue on how to do it?

    I tried using this script but it randomizes all the videos for the whole song, and not per segment. I need to change the video according with de segment so the audio is played according to the sound original order.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5.  
    6. public class Player1 : MonoBehaviour
    7. {
    8.  
    9.     public VideoClip[] VideoClipArray;
    10.     private VideoPlayer videoPlayer;
    11.     private float timeUntilNextVideo;
    12.  
    13.     void Awake()
    14.     {
    15.         videoPlayer = GetComponent<VideoPlayer>();
    16.         videoPlayer.Pause();
    17.     }
    18.     void Start()
    19.     {
    20.         timeUntilNextVideo = 0f;
    21.  
    22.  
    23.     }
    24.  
    25.  
    26.     void Update()
    27.     {
    28.         if (Time.time > timeUntilNextVideo)
    29.         {
    30.  
    31.             videoPlayer.clip = VideoClipArray[Random.Range(0, VideoClipArray.Length)];
    32.  
    33.  
    34.             timeUntilNextVideo = Time.time + (float)videoPlayer.clip.length;
    35.  
    36.             videoPlayer.Play();
    37.         }
    38.     }
    39.  
    40. }
    * Note: The segments hasn't´t the same lenght duration.

    Please help on how to do it!
     
unityunity