Hi, I am kind of new to these forums and have been using Unity for about 5 months.
I have been trying to make a 2d platformer using orthello 2d. I’ve been having some problems with how and when animations of the character play. My main problem is trying to understand how to get an attack animation play once the button is pressed not while its being held which is the only thing I know how to do.
My Code:
if(xa.isLeft !xa.falling !xa.isRuning currentAnim != xa.anim.WalkLeft)
{
currentAnim = xa.anim.WalkLeft;
mySprite.Play("walkLeft");//Run left
}
if(xa.attacking xa.facingDir==1)
{
mySprite.PlayOnce("aLeft" );//Attack Left
xa.attacking=false;
}
if(xa.attacking xa.facingDir==2)
{
mySprite.PlayOnce("aRight");//Attack Left
xa.attacking=false;
}
This contains the code for the animations having both the right and left attack. The walk animation is first to show what I usually do.
The main code in which it is supposed to know when to go to what animation:
in public class xa
public void Update()
{
// these are false unless one of keys is pressed
isLeft = false;
isRight = false;
isUp = false;
isDown = false;
isShoot = false;
isRuning = false;
attacking = false;
// keyboard input
if(Input.GetKey(KeyCode.LeftArrow))
{ isLeft = true; }
if ( Input.GetKey(KeyCode.RightArrow))
{ isRight = true; }
if (Input.GetKey(KeyCode.UpArrow))
{ isUp = true; }
if (Input.GetKey(KeyCode.DownArrow))
{ isDown = true; }
if (Input.GetKey(KeyCode.LeftShift))
{isRuning=true; }
if (Input.GetKey(KeyCode.X) attacking==false)
{
attacking=true;
}
}
For some reason the attack animation should only play once, but once all animations like walking only play once and stop. I dont know why this happens and any suggestions on how to fix this or any better method then what I am doing would be helpful.
Any questions please ask