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

  1. Howgyn

    Howgyn New Member

    Nov 27, 2016
    Likes Received:
    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'?

    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

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer