|
Hi All, I am having all sorts of problems trying to rotate a GUI label on the screen. The following code will work exactly as expected but only if the label is placed in the center of the screen. If labelPosition (the pivot) is anything other than the center of the screen the label winds up in some strange place. It seems that the pivot actually has something to do with the center of the screen whether you like it or not. Help please!
(comments are locked)
|
|
If you want the label to rotate around its own center, then you mustn't use the center of the screen for labelPosition. Try this (I will call R the label's rect) The problem is that if the label's position is anything other than the center of the screen, that the results are not what you would expect. If you take the following code and play with xPosition and yPosition I think you will see what I mean. Any and all help is very much appreciated! var xPosition : float = Screen.width/2; var yPosition : float = Screen.height/2; function OnGUI () { var labelPosition : Vector2 = Vector2(xPosition,yPosition); GUIUtility.RotateAroundPivot (rotateAngle,labelPosition); GUI.Label(Rect(labelPosition.x,Screen.height-labelPosition.y,100,30),"This is the label"); // reset the matrix after rotation GUI.matrix = Matrix4x4.identity; }
May 15 '12 at 09:45 PM
tom@whitebox
Try that one :
#pragma strict
var labelRect : Rect = Rect( 100, 100, 100, 30 );
var pivotOffset : Vector2 = Vector2(0, 0);
var rotateAngle : float = 0.0;
var rotationSpeed : float = 2.0;
private var currTimeRot : float = 0.0;
function OnGUI ()
{
currTimeRot = Mathf.Repeat( currTimeRot + Time.deltaTime * rotationSpeed, 360.0 );
GUIUtility.RotateAroundPivot (rotateAngle + currTimeRot,
Vector2( labelRect.x + pivotOffset.x * labelRect.width,
labelRect.y + pivotOffset.y * labelRect.height ) );
GUI.Label(labelRect, "This is the label");
}
May 16 '12 at 03:17 PM
Berenger
(comments are locked)
|

anyone have any thoughts?