GetCurrentAnimatorStateInfo

Discussion in 'Game Development (Technical)' started by Howgyn, Nov 29, 2016.

  1. Howgyn

    Howgyn
    Expand Collapse
    New Member

    Joined:
    Nov 27, 2016
    Messages:
    2
    Likes Received:
    0
    I want to get the current state from Unity Animator. However when I type theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"), the code "GetCurrentAnimatorStateInfo" is in red line which Visual Studios indicate that "'Game object' does not contain a definition GetCurrentAnimatorStateInfo and no extension method accepting a first argument of type 'Game object' could be found (are you missing using a directive or an assembly reference)"

    When I type anim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"), the code run but the result is not what I want.

    Therefore, I wonder it is necessary to declare something before using 'GetCurrentAnimatorStateInfo'?


    Code:
    void Update()
    {
        GameObject characters = GameObject.Find(charactersname);
        GameObject theanim = GameObject.Find(charactername);
    
        if (!Input.GetKey("up") && !Input.GetKey("down") && !Input.GetKey("left") && !(Input.GetKey("right")) && (anim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk")))
            {
                theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
                theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
                theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
                theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
                theanim.GetComponent<Animator>().SetBool(charactersidlewalk, false);
                theanim.GetComponent<Animator>().SetBool(charactersbackidle, true);
                theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
                theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
            }
    }
    
     

Share This Page