Search Unity

Stop switching animation from any state

Discussion in '2D' started by tito100, Oct 22, 2016.

  1. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Hi all

    I have animations with different weapons. so I have transition from "any state" to state "pistol" when variable "weapon" is equals to 4.
    then I have transition from state "pistol" to state "pistol_idle" when variable "weapon" is equals to 4. And then I have transition from "pistol_idle" to "pistol" when "move" is true.

    But its not working. when I run game, animation is always on state "pistol". Why is animation not move to state "idle". condition "weapon"=4 is true.


    anim.png

    Or how I can make switching weapons.

    Thanks.
     
    Last edited: Oct 22, 2016
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    From the animator window there, when the game is running, you see the parameter "move" become true? You literally see the check box get checked in play mode when you expect it to?
     
  3. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Yes. its checked. only on screen is not checked because I forget checked it.
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I'm asking, during gameplay, if you look at that same window, the animator, while the animated object is selected, does that check box get checked by code like it should? Like without you manually checking it...

    Sorry for asking again, just want to clarify that the code that sets it true is not where the mistake is.
     
  5. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Yes. Its checked by code. And state is always on pistol.
    But Im write bad transition on first post. its

    I have transition from state "any state" to "pistol" when variable "weapon" is equals to 4 then I have from "pistol" to "pistol_idle" when variable "side"=4. and then I have transition from "pistol_idle" to "pistol" when move is true
     
    Last edited: Oct 22, 2016
  6. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    here is screencast. maybe you find whats I have wrong
     
  7. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Im fix it.
    Im add script behavior to state pistol with code:
    Code (csharp):
    1.  
    2. public class onWeapon : StateMachineBehaviour {
    3.  
    4.      // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    5.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    6.         animator.SetInteger ("weapon",0);
    7.     }
    8. }
    9.  
     
  8. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Ok cool, glad you got it working. Good luck!