When using the GUI components in unity, we can shift, scale, and rotate them as we do with an entity.
where displacement and scaling only need to change the contents of their rect, the former changes the x, y parameters, the latter changes the width and height parameters, and the rotation is different, it needs to use a function of Gui.matrix:
Guiutility.rotatearoundpivot (Rotangle, Pivotpoint)
Parameter description:
Rotangle: angle of rotation;
Pivotpoint: The center point around which the rotation occurs.
JavaScript Example:
#pragma strictPrivate varRotangle:float =0;//Angle of rotationPrivate varPivotpoint:vector2;//Center coordinate when rotating function Start(){ //Set Rotation center point to screen centerPivotpoint = Vector2 (screen.width/2, screen.height/2); } function Ongui () { if(GUI. Button (Rect (screen.width/2- the, screen.height/2- -, -, -),"Right")) Rotangle + =Ten;if(GUI. Button (Rect (screen.width/2+ -, screen.height/2- -, -, -),"left")) Rotangle-=Ten;varmatrix:matrix4x4 = Gui.matrix;//Record The matrix at this timeGuiutility.rotatearoundpivot (Rotangle, pivotpoint);//Rotate if(GUI. Button (Rect (screen.width/2- -, screen.height/2- -, -, -),"Hello") {} Gui.matrix = matrix;//matrix recovery so that the left and right buttons do not rotate}
In the example
matrix : Matrix4x4 = GUI.matrix; //记录此时的矩阵
This line of code is to record the Gui.matrix of the GUI interface at this point, and then restore it after the rotation operation (the website says that the rotation interface is successful by changing the value of the variable, such as the following), 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 pivotpoint.
"Learning and using the Unity3d API" unity implements the displacement, scaling, and rotation of GUI components