GUI Rotation and Depth problem

Hello everyone.

I’m using this simple trick to constantly rotate a GUI.DrawTexture element.

// Use this for initialization
	void Start () {
		GameObject tweenObject = new GameObject();
		tweenObject.name = "tweenObject";
		pivotPoint = new Vector2(Screen.width/2, Screen.height/2);
		if (Input.GetKeyUp(KeyCode.Return)) {	//if Enter is pressed
		
		}	
	}
	
	// Update is called once per frame
	void Update () {
		rotAngle = iTween.FloatUpdate(rotAngle, rotAngle+50, 1);
	}
	
	void OnGUI () {
		GUI.DrawTexture(new Rect(Screen.width/2-100, Screen.height/2, 200, 100), LevelUp);
		GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
		GUI.DrawTexture(new Rect(Screen.width/2-100, Screen.height/2-100, 200, 200), StarBurst);
	}

What I’m trying to do, is rotate the StarBurst texture and display the LevelUp texture on top of it without rotating.

Currently the LevelUp texture is not rotating but is behind the rotating StarBurst texture.

If I change the order so the LevelUp texture is drawn second, then it does appear in front but it also rotates together with the StarBurst texture.

Is there anyway to fix this? (without creating another script to draw the non-rotating part)

Thanks!

Save and restore the matrix. Take a look at OnGUI() funciton of @duck’s answer:

http://answers.unity3d.com/questions/11022/how-to-rotate-gui-textures.html