That I need is to rotate each GUI buttons on his axis when the device orientation change.
I found two threads on web about this argument but using these the GUI button rotate but not stop when the device is oriented (Eg; Device oriented in Landscape, the button rotate on his axis continuosly, if the device change orientation in Portrait the button continue to rotate in the previous rotation and not stop.)
So, can how modify this code to change the rotation and stop when the orientation is reached?
Thanks, below the code.
void OnGUI() {
if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) {
rotAngle += 45; }
if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) {
rotAngle -= 45; }
//rotAngle++;
Rect guiRect = new Rect(Screen.width / 2.0f, Screen.height / 2.0f, 128.0f, 128.0f);
float xValue = ((guiRect.x + guiRect.width / 2.0f));
float yValue = ((guiRect.y + guiRect.height / 2.0f));
Vector2 Pivot = new Vector2(xValue, yValue);
GUIUtility.RotateAroundPivot(rotAngle, Pivot);
GUI.Button(guiRect, "Test button");
GUI.matrix = Matrix4x4.identity;
}