Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

make an animation plays only when the first one finishes

Discussion in 'Scripting' started by Warp boy2, Dec 26, 2010.

  1. Warp boy2

    Warp boy2

    Joined:
    Nov 12, 2010
    Posts:
    216
    so im having a huuuuuge problem with this anim

    i have two animations. and i want to make the first one plays completely so then it plays number two

    heres the script i made, along with solutions i tried and didnt worked

    Code (csharp):
    1.  
    2. animation.Play("subweapon1");
    3. animation.CrossFadeQueued("subweapon2");
    4.  
    5. [COLOR="seagreen"](didnt work.. it plays only the first then cut off the secound)[/COLOR]
    6.  
    7.  
    Code (csharp):
    1.  
    2.  
    3. animation.Play("subweapon1");
    4. if (animation.IsPlaying("subweapon1")) { } else {
    5. animation.Play("subweapon2"); }
    6.  
    7. [COLOR="seagreen"](didnt freaking work.. it never evers get to play the secound one)[/COLOR]
    8.  
    9.  

    Code (csharp):
    1.  
    2.  
    3. animation.Play("subweapon1");
    4. animation.Play("subweapon2");
    5.  
    6. [COLOR="seagreen"](didnt work.. it plays then both at the same bloody time..
    7. and since the first one has more frames, i never even notice that it
    8. played the secound)[/COLOR]
    9.  
    10.  
     
  2. enragedmrt

    enragedmrt

    Joined:
    Oct 5, 2009
    Posts:
    95
    Is the second one in a loop? Like in the update? If so, if subweapon1 finally isn't playing at the end of the frame, at the beginning it will play again before it reaches the if() statement so that could be why it never returns false.

    Try this.
    Code (csharp):
    1.  
    2. //Play the Subweapon1 animation when 1 is pressed.
    3. if(Input.GetKeyDown("1")){
    4. animation.Play("subweapon1"); }
    5.  
    6. //Play the subweapon2 animation whenever subweapon1 is not playing.
    7. if (!animation.IsPlaying("subweapon1")) {
    8. animation.Play("subweapon2"); }
    9.  
    I know nothing of animation, but this seems more a problem of logic. (Hopefully I'm correct, lol)
     
  3. Warp boy2

    Warp boy2

    Joined:
    Nov 12, 2010
    Posts:
    216
    it worked!! it worked my friend thanks for that!