Farhan Ali
Farhan Ali

Reputation: 509

Animator state in not checking rather completed or not

In my game I want to check that one state in animator is completed then manually I trigger another state, But I am unable to check that. Any suggestions where I am going wrong, here is code I have done so for, this code is in update function (parameter 'for_fire' and state name 'Standing fire 3' is same for one state):

counter_anim++;
if (counter_anim >= 5) 
{
    counter_anim = 0;
        float distance = Vector3.Distance (this.transform.position, new_target_points);
        if (distance <= 1.0f && !enter_state) 
        {
            navmesh.Stop ();
            anim.SetBool ("is_Firing", false);
            anim.SetBool ("for_fire", true);

            print ("i come here   "+this.anim.GetCurrentAnimatorStateInfo (0).IsName ("Standing fire 3"));

            if (this.anim.GetCurrentAnimatorStateInfo (0).IsName ("Standing fire 3") == true) 
            {
                enter_state = true;  // this bool variable is not getting true
            }
        }
}
//print (enter_state+"     "+ this.anim.GetCurrentAnimatorStateInfo (0).IsName ("Standing fire 3"));

if (enter_state && this.anim.GetCurrentAnimatorStateInfo (0).IsName ("Standing fire 3")==false) 
{
    //print (this.gameObject.GetComponent<Animator> ().GetCurrentAnimatorStateInfo (0).IsName ("Standing fire 3"));

    anim.SetBool ("for_fire",false);
    anim.SetBool ("new_pos",true);
    fire_occured ();
}

I am making like, enemy go to his position and stand their for while and fire, after that this animation stops and next animation starts.

Upvotes: 0

Views: 636

Answers (1)

Hrusilov
Hrusilov

Reputation: 654

Copied from comment:

Even though I've seen some implementations with the IsName() method I usually go for tag if(this.anim.GetCurrentAnimatorStateInfo(0).IsTag("Standing fire 3")). This definitely worked for me. In the Animator than tag your states with it.

My guess is that the name convention didn't work. Maybe you misspelled it or you were using the name of the clip not the state.

Upvotes: 1

Related Questions