- Home /
Method Animator.SetBool sometimes is not working (or not triggering) in Unity2D
I have trouble with Animator in Unity2d. I have a main character for my game. The character has his own animation clip for fighting. When the player touches the screen, i am starting animation. When the player touches the screen slowly (every second) - everything is working fine, but when the player touches the screen fast, the animation clip is playing about 10 times, and then nothing happens (the clip isn't playing). I've checked - the touch event is triggered normaly, may the problem is with animator. Does anyone have ideas how to fix this issue?
public bool UseAxisInput = false;
private Animator Anim;
// Use this for initialization
void Start () {
Anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Anim.SetBool("IsFighting", true);
}
}
}
May be this is because of that at the end of my animation i have an animation event which calls the method, that stops animation.
public void stopFighting()
{
Anim.SetBool("IsFighting", false);
}
Answer by KYL3R · Oct 19, 2017 at 12:05 PM
Ouch, this is old. But anway: You may have transitions set up (default), afaik they can prevent AnimationEvents on the last frame to be called. That might (have been) be one of your problems.
You might want to consider Triggers to start a fighting animation, or even a crossfade
Your answer
Follow this Question
Related Questions
Unity 2d animation acting strange 0 Answers
Scale animation doubt 0 Answers
A node in a childnode? 1 Answer
4.3 messing the animations 3 Answers
2D Animation does not start 1 Answer