- Home /
About AnimatorController
I'll say first. I dont speak English well because Im Japanese.
Something is wrong my script. Some animation is not playing.
Please help me.
function Start()
{
animator = GetComponentInChildren( Animator );
controller = GetComponent(CharacterController);
}
function Update()
{
//jump normal
if( Input.GetButtonDown("Jump") ) {
Debug.Log("jump normal");
direction.y += jumpPower;
animator.SetBool("Jump" , true);
} else {
animator.SetBool("Jump" , false);
}
//jump + direction
if( Input.GetButtonDown("Jump") && Input.GetKeyDown("right") ) {
Debug.Log("jump + direction");
direction.y += jumpPower;
direction.x +=1;
audio.PlayOneShot(footstepsound);
audio.volume = 0.3;
animator.SetBool("Jump" , true);
} else {
animator.SetBool("Jump" , false);
}
//diveR
if( Input.GetButtonDown("diveR") )
{
Debug.Log("diveR");
direction.z +=2;
animator.SetBool("Dive" , true);
} else {
animator.SetBool("Dive" , false);
}
//diveL
if( Input.GetButtonDown("diveL"))
{
Debug.Log("diveL");
direction.z -=2;
animator.SetBool("Dive" , true);
} else {
animator.SetBool("Dive" , false);
}
}
This script is so long, I have omitted several places.
RunningAnimation and WarikingAnimation are play correctly.
What about it? Have you read the docs? http://docs.unity3d.com/$$anonymous$$anual/$$anonymous$$ecanimAnimationSystem.html
Debug.Logs work correctly. Also I have read the docs thatabout$$anonymous$$ecanimAnimationSystem. But $$anonymous$$y Animation is not play.

Answer by CandlewaxJames · Jun 27, 2014 at 04:47 AM
Just at first glance of your code, I noticed that you are using the 'Input.GetButtonDown()' method. This method only returns true for the first frame in which a button is pressed. In your code, on the next frame the animation variables are set to false. This means they are only set to true for one frame and so the animation does not get a chance to play.
I assume the walking and running animations work ok as you are probably checking the horizontal and vertical axis which will remain constantly true whilst they do not equal zero. As opposed to the GetButtonDown() method which is true only for the frame in which the button is pressed.
Your answer