- Home /
Question by
Harryliu · Dec 03, 2014 at 09:18 AM ·
javascriptanimator
How to controll parameters in animator using javascript
I am having trouble with setting up the script here. All i want the character to do is when left shift is pressed set "isRunning" parameter to true and the the key is released go back to original state (idle). I tried using hash id but I couldn't get it to work. Pls help me with the script:
#pragma strict
var anim : Animator;
var runHash : int = Animator.StringToHash("Run");
function Start ()
{
anim = GetComponent("Animator");
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.LeftShift))
{
anim.SetTrigger (runHash);
}
}
Comment
Answer by awesomedata · Dec 29, 2014 at 05:57 PM
You don't want a Trigger here. Try using a Bool instead -- just make it transition back if the Bool is false.
if(Input.GetKeyDown(KeyCode.LeftShift))
{
anim.SetBool("isRunning",true);
}
Then do the reverse for the "else" portion and you're good.
Your answer

Follow this Question
Related Questions
Unity Java - 3D Wall Running First Person Controller 0 Answers
How I can find the complete event of my animation 1 Answer
get a height of a gameobject 1 Answer
I'm confused with the animator 1 Answer