Hello Everyone,
I am trying to pause a video at a particular second. The second/frame should be defined as a public variable. How do I achieve this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
[RequireComponent(typeof(AudioSource))]
public class MoviePlay : MonoBehaviour
{
public GameObject go;
public VideoPlayer movie;
void Start()
{
movie = go.GetComponent<VideoPlayer>();
movie.Play();
}
void Update()
{
if(Input.GetKey(KeyCode.UpArrow) && !movie.isPlaying)
{
movie.Play();
}
else
if(Input.GetKey(KeyCode.DownArrow) && movie.isPlaying)
{
movie.Pause();
}
}
}
Nevermind, I got it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
[RequireComponent(typeof(AudioSource))]
public class MoviePlay : MonoBehaviour
{
public GameObject go;
public VideoPlayer movie;
Ray ray;
RaycastHit hit;
public int Framepause;
public double TimeInSecondsToStart;
public double TimeInSecondsToStop;
private double time;
public float playbackSpeed;
// Use this for initialization
IEnumerator Start()
{
movie = go.GetComponent<VideoPlayer>();
movie.Play();
yield return new WaitForSeconds(0.55f);
movie.Pause();
}
// Update is called once per frame
void Update()
{
//ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// if (Physics.Raycast(ray, out hit) && !movie.isPlaying)
if(Input.GetKey(KeyCode.UpArrow) && !movie.isPlaying)
{
if (movie.canSetPlaybackSpeed == true)
{
movie.playbackSpeed = 1f;
movie.time = TimeInSecondsToStart;
movie.Play();
}
}
else
// if (!Physics.Raycast(ray, out hit) && movie.isPlaying)
if(Input.GetKey(KeyCode.DownArrow) && movie.isPlaying)
{
movie.Pause();
movie.time = TimeInSecondsToStop;
}
}
}
1 Like