Search Unity

[SOLVED] animation controlled by slider

Discussion in 'Immediate Mode GUI (IMGUI)' started by bhaal, Oct 21, 2009.

  1. bhaal

    bhaal

    Joined:
    Apr 18, 2009
    Posts:
    35
    Greetings to all :)

    I made a very simple animation in Maya: 1 cube that is still
    and another object (a sphere) that is translating. I imported
    it into Unity through the FBX.

    In Unity I have only a simple camera and those objects. So my
    question is: how to connect a slider so when I move it the
    animation moves also? I found on a forum this topic:

    http://forum.unity3d.com/viewtopic.php?p=186536&sid=57dec25679eb9bcebf4a195fe70fa6b7

    and a cool script with buttons and slider.

    I tried to attach it to camera but the problem is
    that the buttons doesn`t work properlly. They don`t take into
    account my animation (Take 001) but only the whole time in scene.

    So when I press STOP it stops the current time not my particular
    animation.

    Any idea ?

    PS. I am no programmer so my knowledge in this field is poor
    PS. 2 sorry for my english

    Cheers,
    Lucas
     
  2. bhaal

    bhaal

    Joined:
    Apr 18, 2009
    Posts:
    35
    Well, I tried to make something by myself.

    Code (csharp):
    1. var hSliderValue : float = 0.0;
    2.  
    3. function OnGUI () {
    4.  
    5. hSliderValue;
    6.      animation["Take 001"].time = hSliderValue;
    7.      hSliderValue  = GUI.HorizontalSlider (Rect (25, 25, 100, 30),  hSliderValue, 0, 1);
    8. }
    I also changed the WrapMode to ClampForever so I can go back with my slider when i reached the end.

    But the problem now is that the animation is shaking all the time. Don`t know why?

    Any suggestions ?

    cheers
     
  3. bhaal

    bhaal

    Joined:
    Apr 18, 2009
    Posts:
    35
    Finally, I made it myself :) just studying the whole day the forum and every possible topic about sliders :D
    To avoid the shaking I added the speed value = 0.

    Maybe someone will need this one day :)

    This is my whole code.

    Code (csharp):
    1. var hSliderValue : float = 0.0;
    2.  
    3. function Start ()
    4. {
    5.    animation["Take 001"].weight = 1;
    6.    animation["Take 001"].enabled = true;    
    7.    animation["Take 001"].speed = 0;
    8. }
    9.  
    10. function Update ()
    11. {
    12.  animation["Take 001"].time = hSliderValue;
    13. }
    14.  
    15. function OnGUI () {
    16. hSliderValue  = GUI.HorizontalSlider (Rect (25, 25, 100, 30),  hSliderValue, 0, 1);
    17. }
    cheers,
    lucas