I am trying to get an animation to play through all the way but it doesn't. The code I am using is:
function Update (){
if(Input.GetKeyDown("joystick button 2"))
{
animation.Play("HiroXAttack1");
// name of the animation clip
}
}
======================================================================================================================================================
I have to press the button repeatedly to play the entire animation through.
I tried a different approach and did:
var isAttacking = false;function Update ()
{
if(Input.GetKeyDown("joystick button 2"))
{
isAttacking = true;
}
if(isAttacking)
{
animation.Play("HiroXAttack1");
}
if(Input.anyKey == false)
{
isAttacking = false;
animation.Stop();
}
}
=======================================================================================================================================================================
Your first code snippet should work, provided you have set your animation mode to Once, or Clamp, or ClampForever.
function Update (){
if(Input.GetKeyDown("joystick button 2"))
{
animation.wrapMode = WrapMode.Once;
animation.Play("HiroXAttack1");
// name of the animation clip
}
}
==================================================================================================================================================
There is also a solution if you want the animations to be on the same layer. To play a given animation without stopping other animations on the same layer, you need to not use Animation.Play but instead do:
animation["MyOtherAnimation"].enabled = true;animation["MyOtherAnimation"].weight = 1;
animation["MyOtherAnimation"].time = 0;
==================================================================================================================================================
No comments:
Post a Comment