Search Unity

Mecanim Problems

Discussion in 'Scripting' started by marggob, Apr 1, 2013.

  1. marggob

    marggob

    Joined:
    Feb 24, 2013
    Posts:
    65
    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?
     
    Last edited: Apr 1, 2013
    Pulov likes this.
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,413
    On what line number the error is? (copy the complete error log message)
     
  3. marggob

    marggob

    Joined:
    Feb 24, 2013
    Posts:
    65
    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'
     
  4. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Last edited: Apr 1, 2013
  5. marggob

    marggob

    Joined:
    Feb 24, 2013
    Posts:
    65
    Thank you. It worked. :)
     
  6. videoanime

    videoanime

    Joined:
    Sep 28, 2014
    Posts:
    42
    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?