unity rigidbody 2d rotation rounded to 360 degrees

Hi. I’m working on a project where I need the rotation from the rigidbody2d on the player. It needs to be rounded like the image attached, but after one full rotation it just keeps on getting higher, never returning to zero. does anybody know how I can make a script to alter the rotation to what I’m looking for?

sorry for the link, but I currently can’t upload pictures

You can calculate the rotation if you can get it between [0, 360] and then remove 180. I dont use 2d so I dont know exactly the code, but this should give you a idea of what to do. Hope it helps

float newAngle = (currentAngle + 180) % 360 - 180; //this will take in any rotation and turn it into give [-180,179]

% is modulo and will turn f.ex 1% 360 = 1, 361 % 360 = 1. It gives you the remainder if you were to do whole number/integer division.
360 % 360 = 0

Example: currentAngle = 0 → 180 % 360 - 180 = 180 - 180 = 0
currentAngle = 180 → 360 % 360 - 180 = 0 - 180 = -180
currentAngle = -180 → -360 % 360 - 180 = 0 - 180 = -180