Search Unity

Overlapping Animations

Discussion in 'Scripting' started by Akages, Mar 31, 2011.

  1. Akages

    Akages

    Joined:
    Mar 20, 2011
    Posts:
    11
    Hi, I'm pretty new to Unity and Java script and I'm current creating an FPS. When I press 1 to pull out a weapon a animation is automatically played but if I shoot during the animation then the gun freezes halfway and plays the shooting animation. I want to be able to shoot while the gun is still being pulled out without it stopping the animation.

    Here is the code I am using

    Code (csharp):
    1. //attach this script to the object you want the animations to play on when
    2. //clicking the Left mouse button.
    3.  
    4. //Remember the name of your animations!
    5.  
    6.  
    7. function Update ()
    8. {
    9.    if (Input.GetButtonDown("Fire1")) //check to see if the left mouse was pushed.
    10.     {
    11.        animation.Play("Glock_Shoot"); // if pushed play the animation listed within the quotation marks.
    12.     }
    13.    
    14.     //add multiple animations by copying and pasting this code (below for else if) and changing
    15.     //the animation and button.
    16. }
    The animation that is played automatically using the Inspector is called "Glock_Start"
    Also I have tried using animation.CrossFade but this makes the shooting animations buggy and unresponsive
     
  2. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    So basically what you're saying is you want the "Glock_Shoot" animation to play when you fire, but if the "Glock_Start" animation is still playing from when the player chose this weapon, you still want to be able to shoot but you don't want it to play the "Glock_Shoot" animation?

    You could just do:

    Code (csharp):
    1.  
    2. if (Input.GetButtonDown("Fire1")){
    3.     if(!animation.IsPlaying("Glock_Start")){ //if the glock start animation is not playing
    4.         animation.Play("Glock_Shoot"); //play glock shoot
    5.     }
    6. }
    7.  
     
  3. Akages

    Akages

    Joined:
    Mar 20, 2011
    Posts:
    11
    Great thanks, this worked just great :D
    Sadly I've encountered another problem, When I press the W key to move forward I want to play the animation "Glock_Walk", this works except once the animation stops its doesn't start again, I've tried using "animation.wrapMode = WrapMode.Loop;" but that just made all the animations look, also if I spam the W key the animation keeps jumping straight back to the start instead of continuing and only starting agian if it has stopped. Here is the code I'm using:
    Code (csharp):
    1.  
    2. function Update ()
    3. {
    4. if (Input.GetButton("Vertical")) //check to see if the left mouse was pushed.
    5.     {
    6.        
    7.        animation.Blend("Glock_Walk"); // if pushed play the animation listed within the quotation marks.
    8.    
    9.     }
    10. if (Input.GetButtonUp("Vertical")) //check to see if the left mouse was pushed.
    11.     {
    12.        animation.Stop("Glock_Walk"); // if pushed play the animation listed within the quotation marks.
    13.     }
    14. }
     
  4. robattila128

    robattila128

    Joined:
    Sep 10, 2019
    Posts:
    1
    so your problem got answered, you ran into another one and immediatly came here for help instead of spending a few hours trying to fix it yourself? no wonder you haven't been active in almost 10 years.
     
  5. ics_de

    ics_de

    Joined:
    Dec 6, 2017
    Posts:
    27
    When you're angry because you can't find a solution to your problem and you take it out on this guy. wtf.
     
    MikeM1970 likes this.