- Home /
Javascript to control parameters of animator controller
I'm a beginner at scripting and i'd like to make a simple script to define speed (float), direction(float) and a jump boolean wich are the 3 parameters in my animator controller.
How to link them to the parameters in the animator controller?
Thanks for your help
Answer by Lovrenc · Jan 03, 2013 at 05:03 PM
So you control animator values by his setters.
var animator: Animator;
animator.SetBool("jump", true);
Code above would set value for your jump. For float values the command is SetFloat
. Now if i understand you correctly you want to link your animator variables to reflect state of your script variables. You should declare setters and then use them EXCLUSIVELY to set variable values.
function SetJump(value: boolean) {
jump = value;
animator.SetBool("jump", value);
}
EDIT: I never coded in unityscript so if someone could check this is correct, please do.
How would you call an animator controller's parameters in C#?
I haven't been able to find an equivalent.
Answer by sdp · Jan 05, 2013 at 02:34 PM
This worked for me, thanks
var animator : Animator;
function Start () {
animator = GetComponent("Animator");
}
function Update () {
if(Input.GetButtonDown("Jump")) {
animator.SetBool("Jump", true);
}
else {
animator.SetBool("Jump", false);
}
}
function SetJump(value: boolean) {
Jump = value;
animator.SetBool("Jump", value);
}
<3 You're the best. I've spent HOURS looking around for a solution to this ( moving all that c# syntax over to java) and this was all I needed :D
Your answer
Follow this Question
Related Questions
Does anyone have an example of an animator with diagnol locomotion? 0 Answers
Get list of parameters of an AnimatorController 3 Answers
accessing animation states from animator in javascript 0 Answers
Can Mecanim/Animator be used to make Enemy AI's? -1 Answers
How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers