- Home /
How to display exact video by index, property on button click
Hi everyone, I'm developing an App where you can play a video clip. I have around 60 buttons, where I would like tp aatach the game object with this script. But, I can play only next video, and I dont know how to play exact video, for example, how can I choose video 40 t0 be played on button 40. Can Anyone help me please, this script, create an list of videos, so I can play them one by one, but I need, not to play them one after another, but when I press specific button, the correct video from the list is playing, many thanks in advance
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; using UnityEngine.UI; using System.Linq;
public class WorldSpacVideoPlayer : MonoBehaviour { public Renderer playButtonRenderer; public VideoClip[] videoClips; public GameObject[] Buttons;
private VideoPlayer videoPlayer;
private int videoClipIndex = 0;
void Awake()
{
videoPlayer = GetComponent<VideoPlayer> ();
}
// Use this for initialization
void Start ()
{
videoPlayer.targetTexture.Release ();
videoPlayer.clip = videoClips [0];
}
// Update is called once per frame
void Update ()
{
if (videoPlayer.isPlaying)
{
SetCurrentTimeUI ();
}
}
public void SetNextClip()
{
videoClipIndex++;
videoPlayer.clip = videoClips [videoClipIndex];
SetTotalTimeUI ();
videoPlayer.Play ();
}
void SetCurrentTimeUI()
{
string minutes = Mathf.Floor ((int)videoPlayer.time / 60).ToString ("00");
string seconds = ((int)videoPlayer.time % 60).ToString ("00");
}
void SetTotalTimeUI()
{
string minutes = Mathf.Floor ((int)videoPlayer.clip.length / 60).ToString ("00");
string seconds = ((int)videoPlayer.clip.length % 60).ToString ("00");
}
double CalculatePlayedFraction()
{
double fraction = (double)videoPlayer.frame / (double)videoPlayer.clip.frameCount;
return fraction;
}
}