Crouch animation in 2D

hi, I am very knew to unity and do not know many functions. so i have a code in visual studio to control my animations and movements, like Walking, running and jumping.

I now want to make my charachter crouch while i press “s” in the game.
I started to set up the transitions in the animator but all i can get is crouching without standing back up afterwards…
Any help is appreciated !

here is my code to date:

public class ControleurRobotboy : MonoBehaviour
{

    public float vitesse; //vitesse déplacements
    public float impulsion; // saut


    float deplacement; //input
    bool saute; //état de saut
    int nbSauts; // gestion double sauts
    Rigidbody2D rb;      //  \
    SpriteRenderer sr;   //   > efficacité
    Animator anim;       //  /


  
    void Start()
    {
        rb = gameObject.GetComponent<Rigidbody2D>();
        sr = gameObject.GetComponent<SpriteRenderer>();
        anim = gameObject.GetComponent<Animator>();
       
        deplacement = 0;
        saute = false;
        nbSauts = 0;

    }


    void Update()
    {
        deplacement = Input.GetAxis("Horizontal");  //input du clavier -1 +1
        anim.SetFloat("Etat", Mathf.Abs(deplacement));

        // direction du robot
        if (deplacement < 0)
        {
            sr.flipX = true;
        }
        if(deplacement > 0)
        {
            sr.flipX = false;
        }

        // gestion de saut
        if(Input.GetKeyDown("w") && nbSauts < 2)
        {
            anim.SetTrigger("Saut");
            saute = true;
            nbSauts++;
        }


    }


    private void FixedUpdate()
    {
          rb.AddRelativeForce(Vector2.right * vitesse * deplacement);

        if(saute)       
        {
            rb.AddRelativeForce(Vector2.up * impulsion, ForceMode2D.Impulse);
            saute = false;
        }


    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        nbSauts = 0;
    }

}

The way I did it was to call and play the animation from the script itself without transitions, as for me blending of animations is not required for a 2D pixel game.

You could basically create a bool “isCrouching”, then under Update function, use a condition to set it.
Like if (Input.GetKey(“s”)) { isCrouching = true; else false;
Somthing like that, then you could simple write another condition to play the animation.
Like: if (isTouchingGround) { if (isCrouching) { anim.Play(“animationName”) } else {anim.Play(“animationName”)}

This is without using the visual aid on Unity.

I will try that ! thx !

Sure np, just bare in mind I am new also to Unity, I’ve been using it only for 2 months now.
Using the Animator from the script directly for pixel art works for me, it makes life easier and less confusing.
That being said I am not sure if this method of Animation control is sufficient and flexible.
There are still things I need to figure out how do to from the script, I’m still learning as I go along.

I am not sure if I am allowed to share links from youtube, but search on Youtube a video called “Escaping Unity Animator Hell” lol its a friendly beginners guide how to control it simply from the script. I use his method for now, but I need to figure out how to control play time of animations through the script. I will actually post later a question about a dillema I have in implementing through the script some code to sync animations with projectiles.