Search Unity

Unstable Gun Animations

Discussion in 'Scripting' started by doomlazy, Jul 26, 2014.

  1. doomlazy

    doomlazy

    Joined:
    Aug 24, 2013
    Posts:
    44
    My script should make it so I can play the running animation and shoot or idle and shoot but after I reload the shoot animation wont play anymore. Please help. There is no error.

    Here is my script:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var bullets : int;
    4. var runAnimPlaying : boolean;
    5.  
    6. function Start()
    7. {
    8.     bullets = 10;
    9.     runAnimPlaying = false;
    10. }
    11.  
    12. function Update ()
    13. {
    14.     if(Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))
    15.     {
    16.         runAnimPlaying = true;
    17.     }
    18.     if(Input.GetKeyUp(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))
    19.     {
    20.         runAnimPlaying = false;
    21.     }
    22.     if (runAnimPlaying == true)
    23.     {
    24.         animation.CrossFade("Run");
    25.     }
    26.    
    27.     if(bullets > 0 && Input.GetMouseButtonDown(0))
    28.     {
    29.         bullets -= 1;
    30.         animation.Stop("Run");
    31.         animation.Stop("Idle");
    32.         animation.Play("Shoot");
    33.     }
    34.  
    35.     if(Input.anyKey == false)
    36.     {
    37.         animation.CrossFade("Idle");
    38.     }
    39. }
    40.  
    41. function ReloadGun()
    42. {
    43.     yield WaitForSeconds (0.8);
    44.     bullets = 10;
    45. }
     
  2. doomlazy

    doomlazy

    Joined:
    Aug 24, 2013
    Posts:
    44
    I fixed it. I forgot to add the "if input R reload"