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!!!

3 Answers

3

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.

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 :frowning:
Thanks again for the reply!!

In your code you have the MovieTexture var movTexture : MovieTexture; 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();

You just have to stop the movie

if (movTexture.isPlaying)
movTexture.Stop();
movTexture.Play();