Search Unity

Question IsTag() problem

Discussion in 'Animation' started by unity_uGIyCg-Za_dWTw, Jan 30, 2021.

  1. unity_uGIyCg-Za_dWTw

    unity_uGIyCg-Za_dWTw

    Joined:
    Oct 24, 2020
    Posts:
    2
    I wanted to prevent my character from moving until a combat animation finished playing, therefore, to do so, I tried using IsTag to know whether or not the combat animation was playing. However, using Debug.Log, IsTag always returns false no matter what I try.

    playerAnim.SetTrigger("LightAttack");
    StartCoroutine(WaitForAnimation(playerAnim.GetCurrentAnimatorStateInfo(0)));

    IEnumerator WaitForAnimation(AnimatorStateInfo stateInfo)
    {
    while (stateInfo.IsTag("Combat")==true)
    {
    playerRB.velocity = Vector2.zero;
    canMove = false;
    }
    yield return canMove=true;
    }
     
  2. unity_uGIyCg-Za_dWTw

    unity_uGIyCg-Za_dWTw

    Joined:
    Oct 24, 2020
    Posts:
    2
    Never Mind, I managed to find a way to reach my goal by using this extract of code and a list containing all of the names of my animation states. PS Check is located in the Update function

    void Check()
    {
    if (playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[0]) == true || playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[1]) == true || playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[2]) == true || playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[3]) == true || playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[4]) == true || playerAnim.GetCurrentAnimatorStateInfo(0).IsName(L[5]) == true)
    {
    canMove = false;
    }
    else
    {
    canMove = true;
    }
    }