Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RamiT · Mar 15, 2015 at 07:43 PM · animationjavascriptuislider

How to check if slider is moving?

Hey, how to check if slider is moving? It should do this stuff when moving and then stop when not moving slider.

 import UnityEngine.UI;
 
 var obj = GameObject("");                                
     var animName = obj.GetComponent.<Animation>();            
         var whatAnimation = "";                                    
         
 var animWrapMode = WrapMode.PingPong;
 
 var SliderPos : float;
 var animationSlider = GetComponent(UnityEngine.UI.Slider);
 
 var movingSlider = false;
 
 function Start () {
     
     animationSlider.direction = Slider.Direction.LeftToRight;
     animationSlider.minValue = 0;
     animationSlider.maxValue = 1;
     
     animName[whatAnimation].enabled = false;             
     animName[whatAnimation].weight = 1;                    
     animName[whatAnimation].wrapMode = animWrapMode;    
         
     }
     
 function Update() {
     animName[whatAnimation].normalizedTime = SliderPos; 
         //movingSlider = false;
     
     if(movingSlider) 
     {
     animName[whatAnimation].enabled = true;             
     }
     else
     {
         animName[whatAnimation].enabled = false;             
     }
     
     }
 
 function moveSlider(newPos : float) {
     SliderPos = newPos;
 }




This piece is where things should be changed

 if(movingSlider) 
      {
      animName[whatAnimation].enabled = true;             
      }
      else
      {
          animName[whatAnimation].enabled = false;             
      }
      

Comment
Add comment · Show 1
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 raulrsd · Mar 15, 2015 at 07:52 PM 0
Share

I think you could try with animation.isPlaying()

http://docs.unity3d.com/ScriptReference/Animation.IsPlaying.html

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by Mmmpies · Mar 15, 2015 at 08:14 PM

Look at the slider in the Inspector. At the bottom is an OnValueChanged. Click on the + and in the slot that appears drag the gameObject with your script on it to that.

Add a public function to your script to set a bool to true and record the Time.time when it set to true as a float.

Then in Update if that bool is true play the animation and check if Time.time is greater than that float, if it is set the bool to false so the next frame the animation doesn't play.

Now back to OnValueChanged from the dropdown select YourScriptName -> YourPublicFunctionName.

Hope that makes sense! :¬)

Comment
Add comment · Show 12 · 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 RamiT · Mar 16, 2015 at 12:39 PM 0
Share

Thanks for answer, Sorry I didn't understand this ".. and record the Time.time when it set to true as a float.

Then in Update if that bool is true play the animation and check if Time.time is greater than that float, if it is set the bool to false so the next frame the animation doesn't play."

 import UnityEngine.UI;
 
 var obj = GameObject("");                                
     var animName = obj.GetComponent.<Animation>();            
         var whatAnimation = "";                                    
         
 var animWrap$$anonymous$$ode = Wrap$$anonymous$$ode.PingPong;
 
 var SliderPos : float;
 var animationSlider = GetComponent(UnityEngine.UI.Slider);
 
 var movingSlider = false;
 
 var slider$$anonymous$$oves= false;
 
 function Start () {
     
     animationSlider.direction = Slider.Direction.LeftToRight;
     animationSlider.$$anonymous$$Value = 0;
     animationSlider.maxValue = 1;
     
     animName[whatAnimation].enabled = false;             
     animName[whatAnimation].weight = 1;                    
     animName[whatAnimation].wrap$$anonymous$$ode = animWrap$$anonymous$$ode;    
         
     }
     
 function Update() {
     animName[whatAnimation].normalizedTime = SliderPos; 
 
     
     if(slider$$anonymous$$oves > moveSlider.newPos) 
     {
         animName[whatAnimation].enabled = true;             
     }
     else
     {
         animName[whatAnimation].enabled = false;             
     }
     
     }
     
     
     
 
 function moveSlider(newPos : float) 
 {
     SliderPos = newPos;
 }
 
 function isSlider$$anonymous$$oving(slider$$anonymous$$oves : float) 
 {
     slider$$anonymous$$oves = Time.time;
 }
 
avatar image Mmmpies · Mar 16, 2015 at 01:14 PM 0
Share

Caught me at a bad time as I dont have Unity available but can you clarify if you want the animation to play when the pointer moves the slider and is it a set animation just to show tge sliders moving or do you want to rotate an object with the slider for example?

avatar image RamiT · Mar 16, 2015 at 01:20 PM 0
Share

Yes this script controls animation with slider that works just fine, but object shakes so it's better to stop animation playing somehow when not moving slider(?)

avatar image Mmmpies · Mar 16, 2015 at 01:29 PM 0
Share

Well it depends how you want it to work. If you don't $$anonymous$$d the animation playing when the pointer is clicking the slider but not moving you could set up an event trigger for pointer up to stop the animation.

avatar image Mmmpies · Mar 16, 2015 at 02:34 PM 0
Share

Also as I won't have Unity for a few hours any chance you could post a youtube video so I can see What's happening?

Show more comments

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

How to control animation with UI slider? 2 Answers

UI Slider, Save Values and Change Them 0 Answers

Dynamic Values in Animation Clip 0 Answers

Wait for animation to finish and do something 1 Answer

How to make a button that opens and closes a tab? 1 Answer


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