Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mecanim Transitions

Discussion in 'Animation' started by TheChronicPhenix, Jan 18, 2014.

  1. TheChronicPhenix

    TheChronicPhenix

    Joined:
    Jan 14, 2010
    Posts:
    874
    Ok so I've recently just gotten back into Unity, and the whole mecanim thing is totally new to me, I'm very much used to the old system. I figured out a good deal of it, but a few things confuse me and I think I've run into a bug, though it might just be me setting it up poorly.

    Ok first things first, after much struggling with the new system I got all the animations on my characters and enemies working and playing correctly, but the problem now is the players weapon. It's a very basic setup, the weapon has two animations, I through it on the character (just a capsule at this point), then I did the whole animator and transistions setup, very simple stuff. But I ran into a problem. Either I use a bool to activate the shooting animation, and turn it on and off, or I use the trigger paramater. I tried using a bool first, I just had very simple code.

    Code (csharp):
    1.  
    2. if(Input.GetKeyDown("Fire1")){
    3.      anim.SetBool("Shoot", true);
    4.      yield return new WaitForSeconds(0.5f);
    5.      anim.SetBool("Shoot", false);
    6. }
    7.  
    If the waitforseconds is anything below o.5 the animation will activate maybe once out of every 15 clicks. Otherwise it mostly works. Then I read up on the trigger paramater, and tried using that. So I read that it gets used once and then resets itself, so I was like ok, sounds like exacty what I need. So I tried it, but the gun won't stop shooting... It just keeps playing the shooting animation over and over.

    I can provide pictures of the setup if necessary, it's all very basic stuff though.

    If anyone could provide a better explanation for trigger and how it works, or if someone has used mecanim on semi-auto weapons or the like I'd be very grateful for help. Thanks


    EDIT: Also while this topic is here, Animator.GetCurrentAnimatorStateInfo(0).IsName() does not seem to work when playing animations directly from Animator.Play(), is that on purpose? if so is there an alternative to see when the animation is done playing? Either I figure out how to use Play() or I get the stuff above working right with transitions. Maybe it's just me I mean I know the system is entirely new, it just doesn't seem very well documented
     
    Last edited: Jan 18, 2014