Unity transform.Rotate GetKeyDown and dont rotate again if facing direction?

Hello super new to c# and Unity. I have an empty game object as a child of my player. I have it set up so that when I press my left or right direction buttons the empty rotates with my player using a very short script on the empty object itself. This is for prefab shooting. I was wonder how to make it so if I push the directional button again and I am already facing said direction it dosnt just rotate 180 degrees again. Thank you.

// Update is called once per frame
void LateUpdate()
{
    {
        if (Input.GetKeyDown(KeyCode.A))
            transform.Rotate(0f, 180f, 0f);   
}
    {
        if (Input.GetKeyDown(KeyCode.D ))
            transform.Rotate(0f, -180f, 0f);
    }

}

}

Instead of -

transform.Rotate(0f, 180f, 0f);

Use this-

transform.Rotate(0f, transform.rotation.y + 180f, 0f);

So your code should look like this at the end -

 void LateUpdate()
 {
     {
         if (Input.GetKeyDown(KeyCode.A))
             transform.Rotate(0f, transform.rotation.y + 180f, 0f);   
 }
     {
         if (Input.GetKeyDown(KeyCode.D ))
             transform.Rotate(0f, transform.rotation.y - 180f, 0f);
     }
 }