Compass Bar GUI Help!

I need some help with making a compass gui. Not like the standard circular GUI though. One that scrolls and looks like this: (It’s Horrible, sorry. Hopefully you get what I mean)

Anyways, I’ve tried to do different ways and it never works. Can anyone help please? :slight_smile:

Thank you!

Here is a quick example. First you need to use this texture:

It takes the angle from a target object. It is currently setup so that Vector3.forward is north making Vector3.right east, Vector3.left west, and Vector3.back south.

#pragma strict

var target : Transform;
var compassTex : Texture;

private var displayRect : Rect;
private var texRect : Rect = Rect(0,0,3.0/8.0, 1.0);
var factor = 1.0;

function Start() {
	displayRect = Rect(Screen.width / 2 - 400, 10, 300, 32);
}

function OnGUI() {
	var angle = Mathf.Atan2(target.right.z, target.right.x) * Mathf.Rad2Deg;
	texRect.x = 5.0 / 16.0 + angle / 90.0 / 8.0;
	GUI.DrawTextureWithTexCoords(displayRect, compassTex, texRect);
}

I designed the long graphic so that the code did not depend on the graphic wrapping. If you are sure that the devices you are going to use support wrap mode for images, then you could significantly shorten this image. Plus I probably made it longer than necessary even for a non-wrapping solution.

This is a quick example with code that is highly dependent on the graphic I’ve used. It could easily be generalized, but I leave that to you.

Just have a plane with that width and height and put that exact texture on it.