- Home /
UI controls for video
I am trying to make a set of controls (pause/play) for a video in unity world space, with this much so far...
using UnityEngine; using System.Collections; using UnityEngine.UI; [RequireComponent (typeof(AudioSource))]
public class playVideo : MonoBehaviour {
public MovieTexture movie;
public AudioSource audio;
public bool playVid = true;
// Use this for initialization
void Start () {
{
GetComponent<RawImage> ().texture = movie as MovieTexture;
audio = GetComponent<AudioSource> ();
audio.clip = movie.audioClip;
movie.Pause ();
audio.Pause ();
}
public void playIt(){
if (playVid = false)
{
movie.Pause ();
audio.Pause ();
}
else if (playVid = true)
{
movie.Play ();
audio.Play ();
}
}
}
but I can't get a button click to change the bool state, any ideas? Thanks for the help !
What do you mean by "I can't get a button click" ? Button is not working ? Unclickable ?
I have a button set up with an OnClick event that calls playIt and enables the bool, it does not start the video
Answer by whoseline · Jul 17, 2015 at 12:03 PM
make a canvas . add toggle in it . change your script like this :
void Start()
{
playVid=false;
}
void Update()
{
if(playVid==true)
{
movie.Play ();
audio.Play ();
}
else
{
movie.Pause ();
audio.Pause ();
}
}
public void playIt()
{
playVid=!playVid;
}
and link this playIt method to your toggle button .
I hope it works .
edit : I added playVid=false; to void Start(). can you try this ? let me know if it works .
thanks, but now it plays (at 2x speed for some reason) right off the bat, not at the button click.
it is getting there, the click is working now, just trying to figure out why it is playing fast, like a fast forward version.
Thanks for your help!
Your answer
Follow this Question
Related Questions
Fetching a Video Ad Before the Ads Scene is Loaded 0 Answers
3D Video within Scene 1 Answer
How to make sure everything's working fine in Unity Ads? 0 Answers
Streaming Video Player - Android 1 Answer