[Unity3D API learning and use] Unity achieves the displacement, scaling, and rotation of GUI components, unity3dunity
When using GUI components in Unity, we can perform operations like moving, scaling, and rotating an object.
Here, both displacement and scaling only need to change the Rect content. The former changes the x and y parameters, the latter changes the width and height parameters, and the rotation is different, it requires GUI. A function of matrix:
GUIUtility. rotatearoundity (rotAngle, effectpoint)
Parameter description:
RotAngle: rotation angle;
PivotPoint: the center point around which the image is rotated.
JavaScript example:
# Pragma strictprivate var rotAngle: float = 0; // Rotation Angle private var rotation tpoint: Vector2; // The Center Coordinate function Start () during rotation () {// set the center of rotation to Screen center effectpoint = Vector2 (Screen. width/2, Screen. height/2);} function OnGUI () {if (GUI. button (Rect (Screen. width/2-75, Screen. height/2-100, 50, 50), "right") rotAngle + = 10; if (GUI. button (Rect (Screen. width/2 + 25, Screen. height/2-100, 50, 50), "left") rotAngle-= 10; var matrix: Matrix4x4 = GUI. matrix; // record the current matrix GUIUtility. rotateAroundPivot (rotAngle, rotate tpoint); // rotate if (GUI. button (Rect (Screen. width/2-25, Screen. height/2-25, 50, 50), "Hello") {} GUI. matrix = matrix; // restore the matrix so that the left and right buttons are not rotated}
In the example
Ar matrix: Matrix4x4 = GUI. matrix; // records the matrix at this time.
This line of code records the GUI at this time. matrix, and then it will be restored after the rotation operation (the rotation interface mentioned on the official website is successful by changing the value of this variable, as shown below, so that the left and right buttons are not rotated, but only the Hello button is rotated.
Helper function to rotate the GUI around a point.
Modifies GUI. matrix to rotate all GUI elements angle degrees around tpoint.