I have a Canvas with a 2d drawing (vectrosity) on it and i want to place labels at each line.
So i need to place horizontal and vertical text labels.
private void OnGUI()
{
foreach (var dim in lDimensionLabels)
{
var lText = dim.iMeasurement.ToString();
var l = (int) dim.PositionMeasurement.x;
var b = (int) dim.PositionMeasurement.y;
GUI.Label(new Rect(l, b, 40, 20), lText);
}
}
I tried rotate around pivot but than all my labels rotate.
Can someone give me some sample code to do this?
It’s not clear what exactly you are changing when you rotate. If you select the label you want rotated, you should be able to simply adjust it’s transform or Rect transform’s “rotation value”, probably the Z coordinate. This will rotate the entire label, including the letters, but should not effect other labels.
Oh, in code, to rotate it 90 deg:
Quaternion.Eulers(0,0,90.0f);
label.transform.localRotation = Quaternion.Eulers(0,0,90.0f);; //Also applies any parent object rotatation
or
label.transform.rotation =Quaternion.Eulers(0,0,90.0f); //Does not also apply any parent object rotatation
(Where label is a reference to the control you want to rotate)