Get parameter from the animator?

Hi i am trying to get the parameter boolean from the animator so say if the ilde animation parameter is true then how can i tell the code that it is true or false??

i have tried animator.GetBool(); but cant get it to work thanks.

Not sure if this might work but try (if animator.Playing or this one .IsPlaying){
bool = true;
}

Look at the Mecanim Examples project. It’s free on the Asset Store. The code is there you show you how to use Mecanim.

var animator : Animator;

function Start() {
    animator = GetComponent(Animator);
    var foo = animator.GetBool("idle");
}
1 Like
var animator : Animator;

 function Start() {

    animator = GetComponent(Animator);
    var foo = animator.GetBool((Animator.StringToHash("idle")));
}
1 Like

This won’t actually be any faster. Normally you want to call StringToHash() once to cache a hash value and then use the hash instead of a string for all future references. For example, this would be faster:

var animator : Animator;
var idleID : int;
     
function Start() {
    animator = GetComponent(Animator);
    idleID = Animator.StringToHash("idle");
}

function Update() {
    var foo = animator.GetBool(idleID);
}
6 Likes