Search Unity

Animation (*.anim)

Discussion in 'Scripting' started by PhM340, Jan 16, 2011.

  1. PhM340

    PhM340

    Joined:
    Dec 23, 2010
    Posts:
    8
    Hi,

    I made a little one-minute film on the disassembly of a PC: http://www.vuedehaut.fr/Unity/WebPlayer/PC.html.

    This "film" contains 12 animations (*. anim) for parts of the PC + 1 for the main camera, not using SRIPT, but using only the curves of the windows animation files (*. anim ).

    I should have thought before, but now I want to start all with a button.

    My question is: Is it possible to order by Script (js) all my animations?

    Philippe

    current script only works for the animation of the camera?

    Code (csharp):
    1.  
    2. var beep : AudioClip;
    3.  
    4. animation.Stop();
    5.  
    6. function OnGUI () {
    7.  
    8.     var ScreenX=Screen.width-90;    
    9.     var ScreenY=Screen.height-135;     
    10.  
    11.     GUILayout.BeginArea (Rect(ScreenX,ScreenY,70,125));
    12.  
    13.     if (GUILayout.Button("Auto")){
    14.        
    15.         audio.PlayOneShot(beep);
    16.         animation.Play("0 Animation Camera1");
    17.         animation.Play("1 Animation Capot");
    18.         animation.Play("2 Animation Alim");
    19.         animation.Play("3 Animation driveHDD");
    20.         animation.Play("4 Animation driveSSD");
    21.         animation.Play("5 Animation DVD");
    22.         animation.Play("6 Animation CG");
    23.         animation.Play("7 Animation Coeur");
    24.         animation.Play("8 Animation ventirad");
    25.         animation.Play("9 Animation RAM1");
    26.         animation.Play("10 Animation RAM2");
    27.         animation.Play("11 Animation RAM3");
    28.         animation.Play("12 Animation i920");
    29.     }
    30.  
    31.     if (GUILayout.Button("Manuel")){
    32.         print ("Bouton Manuel");   
    33.         audio.PlayOneShot(beep);
    34.     }
    35.  
    36.     if (GUILayout.Button("RAZ")){
    37.        
    38.         audio.PlayOneShot(beep);
    39.         animation.Stop("0 Animation Camera1");
    40.         animation.Stop("1 Animation Capot");
    41.         animation.Stop("2 Animation Alim");
    42.         animation.Stop("3 Animation driveHDD");
    43.         animation.Stop("4 Animation driveSSD");
    44.         animation.Stop("5 Animation DVD");
    45.         animation.Stop("6 Animation CG");
    46.         animation.Stop("7 Animation Coeur");
    47.         animation.Stop("8 Animation ventirad");
    48.         animation.Stop("9 Animation RAM1");
    49.         animation.Stop("10 Animation RAM2");
    50.         animation.Stop("11 Animation RAM3");
    51.         animation.Stop("12 Animation i920");
    52.     }
    53.    
    54.     if (GUILayout.Button("Com'3D")){
    55.         print ("Bouton Web");
    56.         audio.PlayOneShot(beep);
    57.         Application.OpenURL ("http://www.com3d.fr/");
    58.     }
    59.  
    60.     if (GUILayout.Button("Quitter")){
    61.         audio.PlayOneShot(beep);
    62.         Application.Quit();
    63.     }
    64.  
    65.     GUILayout.EndArea();
    66. }
    67.  
    68. @script RequireComponent (AudioSource)
    69.  
    70.  
     
    Last edited: Jan 16, 2011
  2. Vicenti

    Vicenti

    Joined:
    Feb 10, 2010
    Posts:
    664
    'Course it is.

    Code (csharp):
    1. var animations : String[];
    2.  
    3. function PlayAnimationsInOrder() {
    4.   for ( var s in animations ) {
    5.     animation.PlayQueued( s );
    6.   }
    7. }
    8.  
    9. function Stop() {
    10.   animation.Stop();
    11. }
    (What you're doing is playing them all at once; the one with highest priority will be the only one playing.)
     
  3. PhM340

    PhM340

    Joined:
    Dec 23, 2010
    Posts:
    8
    Hi,
    Thank you for this method.
    It is possible that I did not understand how to apply this method because it does not work.
    But I just realized something, if I want to trigger animations with the script.
    Currently, all my animations are 60 seconds, even if some have their event at the end of 50 seconds ....
    I'm going to reduce all the animations to the "event" in script and order their actions and their durations.
    It is perhaps here that my method blocks?
    Philippe
     
  4. udit014patel

    udit014patel

    Joined:
    Dec 9, 2019
    Posts:
    3
    Hi,
    I want to achieve something similar to this but each animation should run in a sequence on each button click like a video player with play, pause, next and previous. I have functional implementation for this using if else but dont thing its feasible for 30 more animation.


    public void nextSq()
    {

    if (CPU_Model.GetCurrentAnimatorStateInfo(0).IsName("Parent_1"))
    {

    CPU_Model.Play("Parent_2", -1, 0f);
    CPU_Model.speed = 0.25f;
    }

    else if (CPU_Model.GetCurrentAnimatorStateInfo(0).IsName("Parent_2"))
    {

    CPU_Model.Play("Parent_3", -1, 0f);
    CPU_Model.speed = 0.25f;
    }
    else if (CPU_Model.GetCurrentAnimatorStateInfo(0).IsName("Parent_3"))
    {

    CPU_Model.Play("Parent_4", -1, 0f);
    CPU_Model.speed = 0.25f;
    }

    }

    If you have any idea please guide