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
1
Question by VamshiKrishnaP · Nov 18, 2014 at 10:08 AM · animationtimesliderplayframes

How to Control the Animation using Slider ?

Hi All,

I have a 3D model with 20 seconds of Animation time.I need real time control on animation using Slider ( like movie player seek bar ).

Suppose my slider value is 0-20 and if i place the slider value as 10, animation should play from 10th second.

Can anyone suggest the solution ?

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
2

Answer by Rodlaiz · Feb 22, 2017 at 02:57 PM

The solution provided by Vfxjex doesn't work for me because the Animation component has to be marked as Legacy. I try this solution using Animator instead of Animation and it works for me:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class ControlAnimation : MonoBehaviour
 {
     private Animator anim;
     public Slider slider;   //Assign the UI slider of your scene in this slot 
 
     // Use this for initialization
     void Start()
     {
         anim = GetComponent<Animator>();
         anim.speed = 0; 
     }
 
     // Update is called once per frame
     void Update()
     {
         anim.Play("YourAnimationName", -1, slider.normalizedValue);
     }
 }

Comment
Add comment · Show 2 · 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 monotoan · Jun 28, 2017 at 05:23 PM 0
Share

Yep, this works for the new Animator system!

Wish there was some way to deprecate / downgrade all the help/forum answers on the internet that still apply to the old Legacy Animation system. Really confusing having to weed through both.

avatar image twin_digital · Jul 31, 2018 at 12:01 PM 0
Share

Solution worked for me, thanks !

avatar image
0

Answer by HarshadK · Nov 18, 2014 at 10:28 AM

Use AnimationState.time to go to specific time from your animation like:

 animation["AnimationClip"].time = 10.0f;

Now you can set the 10.0f value to be the value you set by your slider. Something like below in C#:

 using UnityEngine.UI;  // Needs to be included at the top in order to be able to access the new UI elements.

 Slider mySlider; // Assign your slider you want to use to control the animation time.

 animation["AnimationClip"].time = mySlider.value;



Comment
Add comment · Show 2 · 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 VamshiKrishnaP · Nov 18, 2014 at 10:44 AM 0
Share

Thank you , Let me check !!!

avatar image lengzai96 · May 05, 2015 at 06:48 AM 1
Share

Now is there a way to use Time.deltaTime() to control the slider movement?

avatar image
0

Answer by vfxjex · Aug 25, 2015 at 02:56 AM

try this code

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class AnimControl : MonoBehaviour {
     Animation anim;
     public Slider slider;
 
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animation> ();
         anim.Play ("SphereAnim");
         anim ["SphereAnim"].speed = 0;
     }
     
     // Update is called once per frame
     void Update () {
         anim["SphereAnim"].time = slider.value;
     }
 }
 

you need to play your animation so you can update via slider and just make the animation speed to zero.

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

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Stop and Stay 1 Answer

How to control animation with UI slider? 2 Answers

Animation Control by frame (use Animation.State.time) 1 Answer

Animation Time? 2 Answers

How to Play an Animation in Unity 4.5.3? 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