compass on GUI rotate with camera!

:cry: i dont know how control to compass rotation when rotate camera!
please help me!

using UnityEngine;
using System.Collections;

public class zhinanzhen : MonoBehaviour
{
    public Texture pan;
    private Rect panRect = new Rect(Screen.width - 270,20, 250, 250); 
	// Use this for initialization
    float zhizhenrotationX = 0F;
    private float sensitivityX =15F;
    float thisAngle;
    public Transform camera;
	void Start () {
	
	}
	
	// Update is called once per frame
	void OnGUI () {
        Matrix4x4 matrixBackup = GUI.matrix;
        if(Input.GetMouseButton(0)){
           
            //zhizhenrotationX = Input.GetAxisRaw("Mouse X") * sensitivityX;
            //thisAngle+= zhizhenrotationX;
           thisAngle= camera.transform.rotation.y * 360;
            Vector2 pos = new Vector2(Screen.width - 270 + 125, 145);

            print( thisAngle);
            GUIUtility.RotateAroundPivot(thisAngle, pos);
            
          
          
        }
        GUI.DrawTexture(panRect, pan);
        GUI.matrix = matrixBackup; 
	}
}

Hi, welcome to the forum!

This code doesn’t look too bad. Can you explain in more detail what is going wrong?

Hi, i did this. I hope it helps:

GUI.skin = compassGUISkin;
		
		var compassAngle : float = transform.rotation.eulerAngles.y;
		var compassDiameter : float = 128;
		var compassWidth : float = 16;
		var compassWindowRect : Rect = Rect (compassPos.x,compassPos.y, compassDiameter, compassDiameter);
		GUI.Label (compassWindowRect, "");
		var cosAngle : float = Mathf.Cos(compassAngle*Mathf.PI/180);
		var sinAngle : float = Mathf.Sin(compassAngle*Mathf.PI/180);
		var xMove : float = (compassDiameter*sinAngle/2.0 + compassWidth*cosAngle/2.0);
		var yMove : float = (-compassDiameter*cosAngle/2.0 + compassWidth*sinAngle/2.0);
		var compassPos : Vector3 = new Vector3(compassPos.x + compassDiameter/2.0 + xMove,compassPos.y + compassDiameter/2.0  + yMove, 0); //position for matrix
		var compassQuat : Quaternion = Quaternion.identity; //rotation for matrix
		compassQuat.eulerAngles = Vector3(0, 0, compassAngle + 90); //set the rotation to something - rotate around z!
		GUI.matrix = Matrix4x4.TRS(compassPos, compassQuat, Vector3.one); //Apply the matrix
		GUI.Box(Rect(0, 0, compassDiameter, compassWidth), ""); //notice how the rect starts at 0/0 and the matrix handles the position

You’ll have to add the variables compassGUISkin and compassPos.

compassPos is a vector2 with the position of the compass

compassGUISkin is a GUISkin with the textures of the compass, in the Label texture use the compassBackground and in the Box texture use the arrow.

You must attach this object to the camera or refer the “var compassAngle : float = transform.rotation.eulerAngles.y;” to the camera.