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 08, 2015 at 01:32 AM · animationjavascriptuisliderplay

How to control animation with UI slider?

So I have problem, how I control animation with UI slider, so if I am moving slider forward it plays animation forward and if backwards it plays animation backwards. I have this script, but it doesn't work anymore in U5 and I have no idea how to make it work with UI slider.

     var sliderPos : float = 0;
     var animationName = "metarig|height";
      
     function Start() {
     animation[animationName].enabled = true;
     animation[animationName].weight = 1;
     }
      
     function OnGUI() {
      
     sliderPos = GUI.HorizontalSlider(Rect(40,40,400,20), sliderPos, 0.0, 1.0);
     animation[animationName].normalizedTime = sliderPos;
      
      
     }
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 RamiT · Mar 10, 2015 at 01:18 PM 0
Share
 import UnityEngine.UI; 
 
 var obj = GameObject(""); 
 var animName = obj.GetComponent.<Animation>(); 
 var whatAnimation = "";
 
 var wrap$$anonymous$$ode = Wrap$$anonymous$$ode.PingPong;
 
 var SliderPos : float; 
 var animationSlider = GetComponent(UnityEngine.UI.Slider);
 
 function Start () {
 
  animationSlider.direction = Slider.Direction.LeftToRight;
  animationSlider.$$anonymous$$Value = 0;
  animationSlider.maxValue = GetComponent.<Animation>().clip.length;
  
  animName.GetComponent.<Animation>().Play(whatAnimation);    
      
  }
  
  
 function Update() {
 
  animationSlider.value = whatAnimation.value;
  animationSlider.value = GetComponent(UnityEngine.UI.Slider).value;
  
  animation[animName].time = GetComponent.<Animation>().normalizedTime = SliderPos;
  
  }
  
 function moveSlider(newPos : float) { SliderPos = newPos; }
 

Still doesn't work I can't get SliderPos to affect animation and even slider wont do anything with SliderPos variable :( help needed.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by RamiT · Mar 10, 2015 at 07:47 PM

I made it work. :D There is code if someone need help with similar problem.

 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);
 
 function Start () {
     
     animationSlider.direction = Slider.Direction.LeftToRight;
     animationSlider.minValue = 0;
     animationSlider.maxValue = whatAnimation.Length;
     
     animName[whatAnimation].enabled = true;
     animName[whatAnimation].weight = 1;
     animName[whatAnimation].wrapMode = animWrapMode;
         
     }
     
 function Update() {
     animName[whatAnimation].normalizedTime = SliderPos;
     }
 
 function moveSlider(newPos : float) {
     SliderPos = newPos;
 }

   
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 Grixen · May 11, 2015 at 12:29 PM 0
Share

Hello RamiT, can you please help to link your script to object position ins$$anonymous$$d UI slider position ?

avatar image RamiT · May 12, 2015 at 03:47 PM 0
Share

Hello! I didn't fully understand what you mean can you tell it more specifically? :)

avatar image
1

Answer by vfxjex · Aug 25, 2015 at 03:07 AM

here's a simple code for C#

     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;
         }
     }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to check if slider is moving? 1 Answer

How to Control the Animation using Slider ? 3 Answers

UI Slider, Save Values and Change Them 0 Answers

Help With Animation Play Back - Reverse 1 Answer

Dynamic Values in Animation Clip 0 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