1
\$\begingroup\$

Recently when I started working on my first animation transition, it has a bug were the transition will occur as soon as the game begins, even though I haven't pressed the key to activate the transition. I would really appreciate any help I can get on this so I can continue creating more animations. I will include my C# code and an image of the transition below. Thanks, Nova

enter image description here

using UnityEngine;
using System.Collections;

public class PlayerAC : MonoBehaviour 
{
    private Animator anim;

    void Start () 
    {
        anim = GetComponent<Animator> ();
    }

    void Update () {

        if (Input.GetButton ("Fire1"))
        {
            anim.SetBool ("RunStright", true);
        }
        else
        {
            anim.SetBool ("RunStright", false);
        }
    }
}
\$\endgroup\$
  • \$\begingroup\$ Do you have an animation component on the GameObject that is set to play automatically? \$\endgroup\$ – user91623 Sep 21 '16 at 16:17
  • \$\begingroup\$ I don't believe so, but I did notice that when has exit time is checked it will run when I click it but, it will only work if I press the key before it reaches the duration line. When I have has exit time not checked it cause the main problem I stated in my question were it plays as soon as it reaches the duration line. \$\endgroup\$ – nova nanite Sep 21 '16 at 19:58
0
\$\begingroup\$

The default value of parameter RunStright is true, you can try unchecking it first before playing, i think this could help.

Edit 1: Added some images to clarify my answer enter image description here

@nova nanite

I don't believe so, but I did notice that when has exit time is checked it will run when I click it but, it will only work if I press the key before it reaches the duration line. When I have has exit time not checked it cause the main problem I stated in my question were it plays as soon as it reaches the duration line.

(Sorry I dont have the privilege to add comment yet)
It doesnt really work when you check the HasExitTime box !

Because when you have that option checked, though the condition of the transition is satifised it must wait until the current animation state finishes, so during the time when you have the first animation state running, the transition can't be activated, even if you want to activate it manually.

So what really happened is that at the moment when you pressed the button the animation was about to finish (i guess the first animation state lasts 1 second), that gave an impression that you activated the transition but no, really, even if you didn't press anything the transition would still occur anyway.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ why the down votes? It can be seen from the screenshot that in parameter list he has RunStright selected, note that in the screenshot Unity editor is not running which means its default value is true, therefore condition of the transition is satifised from the beginning, thats why as soon as he enters the game, the transition is activated. \$\endgroup\$ – tc07 Sep 21 '16 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.