- Home /
Digital Speedometer Help
I searched but couldn't figure it out. My anolog speedometer works fine but I can't seem to figure out how to get the digital display. Here's the code:
var mphDisplay : GUIText; var dialTex: Texture2D; var needleTex: Texture2D; var dialPos: Vector2; var topSpeed: float; var stopAngle: float; var topSpeedAngle: float; var speed: float; var dialTexcircle: Texture2D;
function Update() { speed = Vector3.Dot(rigidbody.velocity, transform.forward); var mph = rigidbody.velocity.magnitude * 2.237; mphDisplay.text = mph + "MPH"; }
function OnGUI() { GUI.DrawTexture(Rect(Screen.width - 240, Screen.height - 250, dialTex.width, dialTex.height), dialTex); var xposition = Screen.width -240; var yposition = Screen.height - 233; var centre = Vector2(xposition + dialTex.width / 2, yposition + dialTex.height / 2); var savedMatrix = GUI.matrix; var speedFraction = speed / topSpeed; var needleAngle = Mathf.Lerp(stopAngle, topSpeedAngle, speedFraction); GUIUtility.RotateAroundPivot(needleAngle, centre); GUI.DrawTexture(Rect(centre.x, centre.y - needleTex.height / 2, needleTex.width, needleTex.height), needleTex); GUI.matrix = savedMatrix; GUI.DrawTexture(Rect(Screen.width - 240, Screen.height - 250, dialTex.width, dialTex.height), dialTexcircle); }
Any help is appriciated!
$$anonymous$$ore detail needed. What's not working? Are you getting a compiler error? A run-time error? Is it just not behaving as expected? If so, in what way?
Sorry um I'm getting the analog speedometer to work and I attach a GUI text but then when I run the game everything works fine, just the GUI text doesn't read out the speed like it should.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123038im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI Text Component Rotate ? 1 Answer
Quick help on a gui script. 1 Answer
How to change font size in ongui function 0 Answers
Why is text so boring in Unity?! 1 Answer
Check if GUI is Pressed 1 Answer