Unity study notes rotate the pit of objects through Euler angles

question

The Rotation in the Transform component in the Inspector panel does not show the real Euler angles.
For example: In the Inspector, the Rotation shows X: 130 Y: 10 Z: 50.
The transform.eulerAngles read by the program will be (50, 190, 230),
insert image description hereinsert image description here
this is because to prevent In the case of universal lock, unity itself will modify the input value.
When the input value is less than 90, transform.eulerAngles is still equal to the input value.
When the input value is greater than 90, transform.eulerAngles is equal to 180 minus the input value

solution

If you use xxx.transform.localRotation = Quaternion.Euler( new Vector(x,y,z)) to control the rotation of the object by inputting the degree of rotation between [0,360], the
input angle x, y, z can be passed through The following judgments are corrected

public float CheckEuler(float angle)
{
    
    
	if (angle > 90 && angle < 270)
		return ((angle) + 180);
    else if (angle > 270 && angle < 360)
		return ((angle) - 360);
    else
		return angle;
}

Guess you like

Origin blog.csdn.net/weixin_42358083/article/details/122364827