Help understanding transform

I’ve got this line of code

baseAngle -= Mathf.Atan2(transform.right.y, transform.right.x) * Mathf.Rad2Deg;

and I’m just trying to understand what this part means

(transform.right.y, transform.right.x)

please explain in detail

Imagine a cube with a rotation of (0,0,0). Imagine an arrow sticking out the right side of that cube. ‘transform.right’ is the direction of that arrow in world space no matter how the cube is turned or twisted.

Mathf.Atan2() generates an angle given an x and a y. It is a bit confusing, but the standard way to use this function is Atan2(y, x). That is, the ‘y’ value is the first parameter. It returns an angle in radians. The angle starts on the right an proceeds counter clockwise.

The use of ‘transform.right’ is pretty typical in 2D games since the objects rotate around their ‘z’ axis. The line of code above figures out the angle the object has been turned around the ‘z’ axis and subtracts it from ‘baseAngle’.