Rotate Texture2D

I’ve got two labels GUI.Label(new Rect(0, 0, 100, 100), _Icon);, where _Icon is a .png file from my resources folder. The thing is I need one _Icon to be rotated 90 degrees cw. Is there any easy and quick way to do it in code?

I don’t want to do it manually by creating extra rotated .png files, because I’ve got >100 of them.

Short answer- No.

Although, the No is only to the third sentence- ‘Easy and quick’.

There is a function inside of GUIUtility which can rotate the ‘canvas’, but it is not exactly ideal for operating on a large number of objects, especially if you don’t know exactly where every object is going to go (using GUILayout, for example). Also, because it operates on the entire UnityGui, you have to reset it carefully after use, otherwise your entire UI will be sideways! If you always know where it is going to go, you could try setting up some kind of wrapper function for rotated GUI elements, which found the centre of your object and rotated it around a given angle before drawing, but it’s a bit of an investment of your time.

If you don’t want to do that, you could try putting all your objects on planes in front of a special orthographic camera which is (along with the planes) on a separate layer that is invisble to the main camera. Then you can set your clear flags to ‘don’t clear’ on the GUICamera, and use normal Transform functions to operate on your gui elements! It’s not exactly the most straightforward of solutions either, but at least it allows you to rotate your icons.