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 unity_PST · Jun 22, 2012 at 05:53 PM · animationguislider

Control an animation with a slider

Does anyone know how to do this? I tried to use animation.sample but didn't quite work.

Comment
Add comment · Show 4
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 whydoidoit · Jun 22, 2012 at 05:58 PM 0
Share

I don't understand what you mean - do you mean a slider?

avatar image unity_PST · Jun 24, 2012 at 01:37 AM 0
Share

yes I mean a slider. sorry about the mis type

avatar image whydoidoit · Jun 24, 2012 at 02:30 AM 0
Share

Thought - so, did my answer get close to what you wanted?

avatar image unity_PST · Jun 24, 2012 at 04:46 PM 0
Share

I didn't yet try it. It seems about same as my version but i used .time ins$$anonymous$$d of normalizedtime and used .sample. I will try your code when I go back home.

5 Replies

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

Answer by whydoidoit · Jun 22, 2012 at 06:37 PM

Well as I'm off for a bit - I will assume you meant how do I control the current position of an animation using a slider:

    var sliderPos : float = 0;
    var animationName = "nameOfAnimation";

    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 · 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 unity_PST · Jun 25, 2012 at 05:20 PM 0
Share

thank you very much I would change .normalizedtime to .time. I am seeing usual results with normalizedtime.

avatar image
1

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

here is a simple code for c#.

 //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"].normalizedTime= 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
avatar image
0

Answer by C-Blunt · Jun 22, 2012 at 06:29 PM

Sounds like iTween could be the answer: http://itween.pixelplacement.com/examples.php scroll down to "Using PutOnPath and PointOnPath", there's plenty of documentation on how to implement it on the itween website itself.

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 kamullis · Jul 03, 2013 at 04:08 PM

This is working for me pretty darn well. I am currently working on getting this to work with a play/pause button as well. Let me know if you want to see what I have for that so far.

 private var hSliderValue : float = 0.0;
 private var myAnimation : AnimationState; 
 
 
 function Start(){
     myAnimation = animation["Take 001"];
 }
  
 function LateUpdate() {     
     myAnimation.time = hSliderValue;
     myAnimation.enabled = true;
      
     animation.Sample();
     myAnimation.enabled = false;  
 }
  
 function OnGUI() {
     // Horizontal slider
     GUILayout.BeginArea (Rect (60,Screen.height - 30,1220,60));
     hSliderValue = GUILayout.HorizontalSlider (hSliderValue, 0.0, myAnimation.length, GUILayout.Width(1200.0f));
     GUILayout.EndArea ();
     
 }
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 gringofxs · Aug 04, 2013 at 04:05 AM

For me work perfect. How can i the size of the touch slider buttom bigger?

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

Unity 5 GUI system 1 Answer

Activating UI panel on GameObject Click/Destroy 0 Answers

Object disappearing after playing animation. 6 Answers

create game and watch style frame by frame animation 0 Answers

How do i make a text box appear on screen after a chest has been opened? 3 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