GetCurrentAnimatorStateInfo
Firstly, if the code compiles and runs, you can ignore what Visual Studio tells you - sometimes the highlighting is wrong.
However, I'd be surprised to see the code run at all since I believe the message is correct - the method you're using is part of the Animator component, not a GameObject. You need to refer to that component, not a game object. If you are saying that changing from "theAnim" to "anim" makes the code compile and run but the answers are not what you expect, there might just be a bug elsewhere in your code.
If that isn't enough to get going, I suggest posting your code.
@Kylotan
Here I attached my code below:
(GetCurrentAnimatorStateInfo) get red line and can't compile in Unity
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")) && (theanim.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);
}
}
You're referring to something called 'anim'. You've not created or declared that object in the code you've posted. The error message suggests that it's a GameObject, which does not contain that method. You probably want to replace that with 'theanim.GetComponent<Animator>()' just like you're doing in the code below it.
Very sorry though ... It is my mistake.
I mistakenly wrote it as anim, actually what I want to wrote is (theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"))
"theanim" make "GetCurrentAnimatorStateInfo" become red line.
'Theanim' is a GameObject, so what I said above still applies. You need the relevant Animator component, just like you do inside the if statement.