I have a game object at 35,0,0. I want to have the degrees printed to the screen around the object every 15 degrees. So people know where they are when they turn around the object. What is the best way to print this text at a fixed distance from the circle so they can always see how far they have rotated from 0? I know I can do graphics for the numbers and load them in the appropriate place but I would like to be able to use a GUI or something to do this automatically that way I can easily change color or size or location.
I am looking to put compass marks around the player camera so they can see which direction they are pointing at all times. I am attaching a rough sketch. I would like to just make 1 major tick and 1 minor tick and place these around the player with a script so I can change the distance around the player easily plus the compass needs to always be around the player wherever they go and stay in the same orientation. Not sure how to do this. Image
(This is for a GUI compass)
The easiest way would be to make a texture with the compass on it, and then use this:
http://unity3d.com/support/documentation/ScriptReference/GUIUtility.RotateAroundPivot.html
to rotate it.
If I recall correctly, [and someone please correct me if I am wrong], the thing rotates everything in the OnGUI function after being called. So in certain scenarios, you might need to do something like this:
public void OnGUI()
{
//do stuff
//rotate y degrees
//draw compass
//rotate back (i.e, rotate -y degrees)
//do other stuff
}
The value y here is easily calculated from the Euler angles of the object (the player) - it is simply `player.transform.rotation.eulerAngles.y`.
To keep text upright, you need to draw it over the rotated texture at the correct screen coordinates. The following should draw a label every 30 degrees:
public void OnGUI()
{
//do stuff
//rotate y degrees
//draw compass texture
//rotate back (i.e, rotate -y degrees)
//draw text
for(int i = 0; i < 12; i++)
{
string label_text = (((i * 360) / 12)).ToString(); //in degrees
float angle = i / 12.0f * 2 * Mathf.PI; //in radians
int x = radius * Mathf.Cos(angle);
int y = radius * Mathf.Sin(angle);
GUI.Label(new Rect(compass_center_x + x, compass_center_y, y, label_width, label_height), label_text);
}
}
Here, `radius` is how far you want the text to be displaced from the center, `label_width` and `label_height` are the dimensions of the label (that of course depend on the font). `compass_center_x` and `compass_center_y` are the screen coordinated of the compass. You will have to use a `GUIStyle` to anchor the text in the center.