How do I get my "snake" to change direction?

I’m trying to recreate snake for learning purposes, and I can’t seem to get my snake to face the direction it’s moving.

private void Update()
{
    if (Input.GetKeyDown(KeyCode.W)) {
        _direction = Vector2.up;
    } else if (Input.GetKeyDown(KeyCode.S)) {
        _direction = Vector2.down;
    } else if (Input.GetKeyDown(KeyCode.A))
    {   _direction = Vector2.left;
    } else if (Input.GetKeyDown(KeyCode.D))
    {   _direction = Vector2.right;
    } else if (Input.GetKeyDown(KeyCode.UpArrow))
    {   _direction = Vector2.up;
    } else if (Input.GetKeyDown(KeyCode.DownArrow))
    {   _direction = Vector2.down;
    } else if (Input.GetKeyDown(KeyCode.LeftArrow))
    {   _direction = Vector2.left;
    } else if (Input.GetKeyDown(KeyCode.RightArrow))
    {   _direction = Vector2.right;
    }
}

How can I make it were for instance, if I press W to go up, he not only moves up, but faces the up direction?

You can simply try this.

transform.up = _direction;

where, transform is your snake game object’s transform.
Simple.

Another way

transform.rotation = Quaternion.LookRotation(_direction);

This will help you, although second one will work for 2D or not I am not sure, As I have not tested this code.