I was thinking about this a few days ago and have decided that this is a must-have for many games.
If I can work out how to do this efficiently and quickly, I will be releasing a small pack of functional UI-driven compasses to the Asset Store, for FREE.
Anyone who can help me achieve this will be given credit for their help in the Documentation PDF file of the pack.
List of Requirements
Accurate, Realistic Compass
Changeable Directionals (Choose whether the X+ or X-, Z+ or Z- will be North)
Masking for areas over 140 degrees
What we are looking for primarily is a solution that would allow us to quickly create compasses that are visibly and functionally similar to those in games such as Skyrim and Fallout.
I gave you some pointers in your last thread about this, but you never responded. Can you be a bit more specific as to what kind of help you’re looking for?
Easiest way is possibly to create an image with N NE S SE etc…, put two of these into a horizontal layout group, add content size fitters to both images as well as the horizonal layout group and then add a mask & scroll rect on top of it. This way, you should be able to scroll through it with values 0<x<1, x=angle/360. Shouldn’t take more than 5-10mins if you have the graphics.
I did exactly this a while back. Have a look at this, this should push you in the right direction.
I know this is OnGUI, but it is relatively simple.
var compTex: Texture2D;
var camAngle: float;
var texWidth: float;
var texHeight: float;
function OnGUI() {
//This is the magic
camAngle = Camera.main.transform.eulerAngles.y;
if (camAngle > 180) {
camAngle -= 360;
}
var compX = Screen.width / 2 - camAngle / 360 * texWidth;
//This just needs to be pushed to new Unity UI.
GUI.DrawTexture(new Rect(compX - texWidth, 0, texWidth, texHeight), compTex);
GUI.DrawTexture(new Rect(compX, 0, texWidth, texHeight), compTex);
}