Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by paritparit · Aug 09, 2011 at 04:03 PM · guitexturemoviereplay

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by TihomirTashev · Sep 01, 2016 at 08:36 AM

You just have to stop the movie

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tnetennba · Aug 09, 2011 at 04:40 PM 0
Share

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();

avatar image paritparit · Aug 09, 2011 at 08:12 PM 0
Share

ok, I will try that, thank you ;)

avatar image paritparit · Aug 09, 2011 at 10:11 PM 0
Share

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 :)

avatar image jfrech · Apr 18, 2012 at 07:33 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges