- Home /
Make a movie texture rewind (play again)
Hello all, I wish someone could help me with this. I am using a movie texture to play my video on a GUI button click.But it only plays one time,the first time I click the button.How do I get it to play again. Im sure Im doing something wrong here, but I really don't know what else to do...
I am using:
var movTexture : MovieTexture;
var cubeRenderer:Renderer;
var playAutomatically : boolean ;
function OnGUI()
{
if(GUI.Button(Rect(10, 10, 150, 20), "PLAY"))
renderer.material.mainTexture.Play();
if(GUI.Button(Rect(10, 30, 150, 20), "Back to main"))
Application.LoadLevel("MainLevel");
}
function Update () {
if (GUI.Button(Rect(10, 10, 150, 20), "Play")) {
if (renderer.material.mainTexture.isPlaying) {
renderer.material.mainTexture.Pause();
}
else
{
renderer.material.mainTexture.Play();
}
}
}
It wont play again,only once, plus, there is a ArgumentException saying: You can call GUI functions from inside OnGUI.
I would really appreciate any help I could get about this. Thank you in advance!!!
Answer by TihomirTashev · Sep 01, 2016 at 08:36 AM
You just have to stop the movie
if (movTexture.isPlaying) movTexture.Stop(); movTexture.Play();
Answer by tnetennba · Aug 09, 2011 at 04:24 PM
If you call stop it will reset it to the beginning of the clip.
http://unity3d.com/support/documentation/ScriptReference/MovieTexture.Stop.html
You should only call GUI code from inside a GUI function i.e. OnGUI not Update.
Answer by paritparit · Aug 09, 2011 at 04:36 PM
Yes, thank you very much for the reply, but... how do I call Stop?? This may seam like a piece of cake to you,but to me is like I have to make a ton of different tries :( Thanks again for the reply!!
In your code you have the $$anonymous$$ovieTexture
var movTexture : $$anonymous$$ovieTexture;
So if you assign the movie texture you wan't to control to that variable then you just have to call the function from it i.e.
movTexture.Play(); movTexture.Stop();
I understand what you mean,but unfortunately I don't know the way to put it all together and make it work, I always get errors which means I am doing it wrong. What Im using now is:
function OnGUI() {
if(GUI.Button(Rect(10, 10, 150, 20), "PLAY"))
renderer.material.mainTexture.Play();
if(!movTexture.isPlaying)
movTexture.Play();
else
movTexture.Stop();
}
This time I didn't get any error message, but it is not playing at all..:/
Could you please tell me what im doing wrong? Im really stuck with this.
Thank you in advance :)
You want to put that if/else statement within your button function. As you have it, every frame it checks if its playing and if it is, it stops. Try this:
function OnGUI() {
//Play/Stop on click
if(GUI.Button(Rect(10, 10, 150, 20), "PLAY"))
{
if(!movTexture.isPlaying)
movTexture.Play();
else
movTexture.Stop();
}
}
Or if you want to keep your play/pause functionality you could do something like this:
var paused : boolean;
function OnGUI() {
//Play/Pause on click
if(GUI.Button(Rect(10, 10, 150, 20), "PLAY"))
{
if(!movTexture.isPlaying)
{
movTexture.Play();
paused = false;
}
else
{
movTexture.Pause();
paused = true;
}
}
//Stop movie if not playing and not paused
if(!movTexture.isPlaying && !paused)
movTexture.Stop();
}
Edit: Forgot to add in setting the paused flag
Your answer
Follow this Question
Related Questions
Move Texture From Plane To GUI And Back 0 Answers
Movie GUI Texture Alpha? 1 Answer
GUITexture Button? 1 Answer
Unity Movie Texture Audio Black Screen 1 Answer
rotating GUI texture by angle 2 Answers