Search Unity

anim.SetInteger isn't working

Discussion in 'Animation' started by unity_synaesthesia, Mar 17, 2019.

  1. unity_synaesthesia

    unity_synaesthesia

    Joined:
    Mar 17, 2019
    Posts:
    4
    I'm working on a mobile 3d game, i've shared a picture from my character's movement script, if you look at it you can see there is an "anim.SetInteger" for each input but the "condition" doen't change to "1" for every direction. If you guys know what do i need to do that, pls let me know.
     

    Attached Files:

  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    That code looks like it should work fine, so your problem is somewhere else. Maybe you're setting the integer back to 0 immediately, maybe you're looking at the wrong object, maybe you don't even have that script attached to the correct object.
     
  3. unity_synaesthesia

    unity_synaesthesia

    Joined:
    Mar 17, 2019
    Posts:
    4
    Else part is something like this. Maybe that's the problem?
     

    Attached Files:

  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    That else only relates to the last if. So regardless of whatever the previous ones do, the last if will either set the int to 1 or 0.

    You likely want to change all the ifs after the first to
    Code (CSharp):
    1. else if
    .
     
  5. unity_synaesthesia

    unity_synaesthesia

    Joined:
    Mar 17, 2019
    Posts:
    4
    I tried it and animations works fine but, right now my character only goes 4 direction, it can't go diagonally
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Honestly that whole logic chain is a mess. I would offer suggestions, but I can't actually figure out what that code is intended to do. For example, the second if will make you move left when the joystick is tilted left and when it's less than 0.2 to the right, but not when it's at 0. It just doesn't make any sense.
     
  7. unity_synaesthesia

    unity_synaesthesia

    Joined:
    Mar 17, 2019
    Posts:
    4
    Whatever i figured out and it's working pretty well