Having trouble getting animations to work

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

You are into an Update(). Then no end to the press detection.

Did you try replacing the Input.GetKey() by Input.GetKeyDown() ?

Welcome to the forum. Those who develolped Orthello, or who are experienced in Orthello may be more suited for answering this type of question. This is one of those times when shouting to all users, like in an mmorpg would be useful lol. Because more and more, the Unity scripting section gets hit with Unity Asset Store product support questions.

Well the thing is when I just want the player to press the attack button (which is x) once so it would attack once. Pressing it multiple times would result in multiple attacks.

Is there no answer to my question or do I have to find a different place to post this?