animation lasts only 1 frame

My “attack” animation plays only on one frame, so it is not visible at all. After one frame it jumps back to “idle” animation. How can I make my character to play the whole attack animation and then fluently go back to idle animation?

public class Player_scr : MonoBehaviour {


	public float movementSpeed;


	void Start () {
		movementSpeed = 5f;
	}
	

	void Update () {
	
		ControllPlayer();
	}


	void ControllPlayer()
	{
		float moveHorizontal = Input.GetAxisRaw ("Horizontal");
		float moveVertical = Input.GetAxisRaw ("Vertical");

		Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
		if(movement != Vector3.zero)
		{
			animation.CrossFade ("walk-01");
		}
		else if(!Input.GetButton ("Fire1"))
		{
			animation.CrossFade ("idle-06");
		}

		if(moveHorizontal != 0 || moveVertical != 0)
		{
			transform.rotation = Quaternion.LookRotation(movement);
		}

		transform.Translate (movement.normalized * movementSpeed * Time.deltaTime, Space.World);

		
		if(Input.GetButtonDown ("Fire1"))
		{
			animation.CrossFade ("attack-06");
		}
	}	
}

It might be a side effect of you constantly telling the character to play an animation every frame. What I see you’re doing is playing the idle animation whenever the “Fire1” key is not hit and only in the frame that “Fire1” is hit you tell it to crossfade to “attack-06”.

What you might want to do is make sure you only tell your character to play the appropriate animation when he starts performing that action instead of while he’s performing the action. This way you only tell your character to play the walk animation for once for instance.

Try this code and see if that works for you. If not then you can check out this video to get a better idea of how to blend animations How to Mix Animations in Unity3D (Legacy) - YouTube

public class Player_scr : MonoBehaviour
{
    public float movementSpeed;

    private const string IdleAnimation = "idle-06";
    private const string WalkAnimation = "walk-01";
    private const string AttackAimation = "attack-06";

    private string currentAnimation = IdleAnimation;


    void Start()
    {
        movementSpeed = 5f;
        animation[WalkAnimation].layer = 1;
        animation[IdleAnimation].layer = 1;
        animation[AttackAimation].layer = 2;
    }


    void Update()
    {

        ControllPlayer();
    }


    void ControllPlayer()
    {
        float moveHorizontal = Input.GetAxisRaw("Horizontal");
        float moveVertical = Input.GetAxisRaw("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        if (movement != Vector3.zero)
        {
            animation.CrossFade(WalkAnimation);
        }
        else
        {
            animation.CrossFade(IdleAnimation);
        }

        if (Input.GetButtonDown("Fire1"))
        {
            animation.Blend(AttackAimation);
        }

        if (moveHorizontal != 0 || moveVertical != 0)
        {
            transform.rotation = Quaternion.LookRotation(movement);
        }

        transform.Translate(movement.normalized * movementSpeed * Time.deltaTime, Space.World);
    }
}