This works fine. But its not really the way i would like to see it. I would prefer to see it as like a bunch of Colorful bars on the button right of the screen. And when i reach higher speeds the lights will increase as it gets to the top speed it be red. I know this sounds confusing and it is but does anyone know of a tutorial or something that could end in result of having a awesome speedometer. thank you.
If you want something like a led VU, use GUI.DrawTexture to draw the bars proportionally to the speed:
var barTexture: Texture2D; // select some white or gray texture
var barWidth: float = 5;
var barHeight: float = 40;
var barSpace: float = 7;
function OnGUI(){
// set the speedometer top-left corner
var pos = Vector2(Screen.width - 90, Screen.height - 50);
// get the speed in mph:
var mph = rigidbody.velocity.magnitude * 2.237;
// draw the bars: each bar means 5 mph, no bar if speed < 1:
for (var v: float = 1; v <= mph; v += 5){
// you can set different colors here:
if (v < 25){
GUI.color = Color.green; // below 25: green
} else if (v < 45){
GUI.color = Color.yellow; // 25 and above but below 45: yellow
} else {
GUI.color = Color.red; // 45 and above: red
}
GUI.DrawTexture(Rect(pos.x, pos.y, barWidth, barHeight), barTexture); // draw a single bar
pos.x += barSpace; // next bar at barSpace pixels to the right
}
}
NOTE: If you want to show the speed numerically too, set the format to avoid tons of digits:
// display the speed with a single decimal digit:
mphDisplay.text = mph.ToString("F1") + " MPH";