I want to get the current state from Animator. The reason I do this is because I want my sprite can approach multiple Idle state. For example, when sprite move left, when it go to idle state, it should go for leftidle instead of front idle. And
However when I type
theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk")) "GetCurrentAnimatorStateInfo" the code is in red line which Visual Studios indicate that
'Game object' does not contain a definition GetCurrentAnimatorStateInfo and no extension method accpeting a first argument of type 'Game object' could be found (are you missing using a directive or an assembly reference)
Below I attach my code:
if (!Input.GetKey("up") && !Input.GetKey("down") && !Input.GetKey("left") && !(Input.GetKey("right") && (theanim.GetComponent<Animator>().GetBool("BackIdle") == true))) { 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); } Below I attach my Unity Animator:
