i have script. static int atakState = Animator.StringToHash("Base.Atak1"); void Start (){ anim = GetComponent<Animator>(); } void FixedUpdate () { currentBaseState = anim.GetCurrentAnimatorStateInfo(0); if (currentBaseState.nameHash == atakState){ Debug.Log("Do Stuff Here"); } } But Unity throws this error. error CS0103: The name `curentBaseState' does not exist in the current context Where is my mistake?
This is not the original script, and extract from it. However, swears to this specific part of it. To be more precise on what these lines. currentBaseState = anim.GetCurrentAnimatorStateInfo(0); if (currentBaseState.nameHash == atakState){ In this case, the error code they identical. Swears by the variable "currentBaseState". If you set the variable "currentBaseState" some type (int, string, float or whatever) int currentBaseState = anim.GetCurrentAnimatorStateInfo(0); it gives this: error CS0029: Cannot implicitly convert type `UnityEngine.AnimatorStateInfo 'to` int'
int currentBaseState = anim.GetCurrentAnimatorStateInfo(0); will never work. The doc's tells you exactly what you expect the return to be: http://docs.unity3d.com/Documentation/ScriptReference/Animator.GetCurrentAnimatorStateInfo.html which is function GetCurrentAnimatorStateInfo (layerIndex : int) : AnimatorStateInfo So what your line should be is: AnimatorStateInfo currentStateInfo = anim.GetCurrentAnimatorStateInfo(0);
Hi, I have a question to you, I have a similar issue, actually I wrote the example in my code and I don´t have errors, but the numbers that are comparing never are the same, I mean, the number of the state I want to find is different from the number that GetCurrentAnimatorStateInfo gives to me, didn´t you have the same problem?