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.

All animations working (idle,walk) except run animation {Help}

Discussion in 'Animation' started by Destayre, Jun 22, 2014.

  1. Destayre

    Destayre

    Joined:
    Apr 19, 2014
    Posts:
    5
    Hey, I kinda need a little help with this, my problem is I have made animations to go with my fps, applied to the animation list component on my weapon which my arms are also in that, i added the script which has no errors.. i play the game and my idle animation works perfectly, my walk animation works awesome, but my run animation just twitches abut when i hold left shift and just continues playing the walk animation when i have a run animation set, the animation is the same name as said in the script and is paired with all the others in the component under my controller/m14(weapon) including my arms... i have tried many solutions.. changing the script around, creating various run animations which works good in the animation preview and ive set on my m14 object to generic, if i set it to legacy nothing plays... and i have gone into the input settings and added a run control with left shift button put in, i added the script below... any thoughts? Script.png
     
  2. Destayre

    Destayre

    Joined:
    Apr 19, 2014
    Posts:
    5
    sorry for the bad quality picture
     
  3. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    Line 10: GetButtonDown -> GetButton
     
  4. Destayre

    Destayre

    Joined:
    Apr 19, 2014
    Posts:
    5
    Thanks for the reply... but when i changed it... came up with this error only: Assets/Gun Script.js(10,23): BCE0017: The best overload for the method 'UnityEngine.Input.GetButton(String)' is not compatible with the argument list '(UnityEngine.KeyCode)'.
     
  5. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    Are you supplying the GetButton(string) method a parameter of KeyCode?

    GetButton should accept a parameter of string.

    is your line 10:

    if (Input.GetButton("Run"))
     
  6. Destayre

    Destayre

    Joined:
    Apr 19, 2014
    Posts:
    5
    This is the whole script with your correction.. sorry im kinda new to scripting so yeah.. comes up with error: expecting eof, found 'else'... here is script:

    function Start () {

    }

    function Update() {
    if(Input.GetAxis("Vertical")){
    // If you go forward or backward...
    if(Input.GetButton("Run"))
    // If you put down left shift...
    animation.CrossFade("Run", 0.1);
    // Crossfade the animation "Run"...

    }
    else
    // If you are not holding left shift...
    {
    animation.CrossFade("Walk", 0.1);
    // Crossfade the animation "Walk"
    }
    }
    else
    // If your not pressing anything
    {
    animation.CrossFade("Idle", 0.1);
    // Crosssfade the animation Idle...
    }
    }
     
  7. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    The { } is not matched.
    Add a '{' at the end of 'if (Input.GetButton("Run")) '

    Code (CSharp):
    1. function Update() {
    2. if(Input.GetAxis("Vertical")){
    3.     // If you go forward or backward...
    4.     if(Input.GetButton("Run")){
    5.     // If you put down left shift...
    6.         animation.CrossFade("Run", 0.1);
    7.       // Crossfade the animation "Run"...
    8.      }
    9.      else
    10.      // If you are not holding left shift...
    11.      {
    12.         animation.CrossFade("Walk", 0.1);
    13.         // Crossfade the animation "Walk"
    14.      }
    15. }
    16. else
    17. // If your not pressing anything
    18. {
    19.     animation.CrossFade("Idle", 0.1);
    20.     // Crosssfade the animation Idle...
    21. }
    22. }
     
  8. Destayre

    Destayre

    Joined:
    Apr 19, 2014
    Posts:
    5