How do i make just my gun to rotate to 180/-180x when i flip?

I can’t get my head around what I exactly to write, so only my gun rotates.
Can anyone help?

parts of script that do flip

[SerializeField] Transform gun;

private void CheckDirection()

    {
        if(isFacingRight && moveHorizontal < 0)
        {
            Flip();
        }
        else if(!isFacingRight && moveHorizontal > 0)
        {
            Flip();
        }
    }

    private void Flip()
    {
        isFacingRight = !isFacingRight;
        transform.Rotate(0f, 180f, 0f);
    }

rotate the gun.transform

Hi! If you stick to the basics, you can do something like this:

[SerializeField] Transform gun;

private void CheckDirection()
{
    Vector3 rotation = gun.eulerAngles;

    if (moveHorizontal < 0)
    {
        rotation.y = 180;
    }
    else if (moveHorizontal > 0)
    {
        rotation.y = 0;
    }

    gun.eulerAngles = rotation;
}

Hope this helps :smiley: