Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AusAndrew19 · May 30, 2012 at 01:47 AM · carsspeedometer

How to create a digital Speedometer.

Hey Guys! I was wondering how would i go about scripting a on screen speedometer. atm im using

var mphDisplay : GUIText;

var mph = rigidbody.velocity.magnitude * 2.237; mphDisplay.text = mph + " MPH";

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AusAndrew19 · May 30, 2012 at 02:34 AM 0
Share

Anymore info you need let me know :)

avatar image dlazardesigns · Nov 21, 2013 at 02:48 AM 0
Share

Is this C# friendly? Every time I put in

  var mphDisplay : GUIText;

I get errors because of the ":". A bit new to scripting, but hoping to stay in C#. How can I address that?

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by aldonaletto · May 30, 2012 at 12:50 PM

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 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";
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AusAndrew19 · May 30, 2012 at 12:56 PM 0
Share

@Aldo Naletto, $$anonymous$$ate... You have done it again... You sir are brilliant. This is exactly what i wanted thank you mate. You sir deserve a medal. Thanks!!!!! :)

edit, Is there anyway to make the colors a little brighter?

avatar image aldonaletto · May 30, 2012 at 02:32 PM 0
Share

The colors Color.green, Color.red etc. are as bright as they could be. I suppose you should try a suitable texture in barTexture to get a "glowing appearance" - maybe the image of a rectangular bright led. Remember to convert the texture to black-and-white - this ensures that all RGB color components have the same intensity in any pixel, allowing GUI.color to control the final color.

avatar image AusAndrew19 · May 31, 2012 at 06:15 AM 0
Share

thank you mate, Really appreciate all your help. :)

avatar image ApplezGaming · Oct 11, 2012 at 09:45 PM 0
Share

very good but $$anonymous$$e only seems to do falling speed not driving speed

avatar image aldonaletto · Oct 12, 2012 at 12:30 AM 0
Share

if you want just the horizontal speed, zero its Y component:

 var vel: Vector3 = rigidbody.velocity;
 vel.y = 0;
 var mph = vel.magnitude * 2.237;

avatar image
2

Answer by tomka · May 30, 2012 at 07:21 AM

Good answer provided here: http://answers.unity3d.com/questions/15414/how-can-i-make-an-on-screen-speedometer.html

Prefab: http://forum.unity3d.com/threads/63885-Car-speedometer-dial

Asset store: http://yusufakdag.com/index.php/2011/09/22/speedometer-ui-for-unity3d/

Top 3 links in google for "unity 3d speedometer" in Google ;) https://www.google.com.au/search?aq=f&sugexp=chrome,mod=7&sourceid=chrome&ie=UTF-8&q=unity+3d+speedometer

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AusAndrew19 · May 30, 2012 at 12:06 PM 0
Share

Thanks for your reply. I have followed that tut and got it working. But its not what im after... Guess i just gotta keep learning untill i can figure this one out for myself. Thank you though

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

I need a speedometer on my car!! 0 Answers

How would i write a script to add a Particle system to an exhaustust 1 Answer

Problem with time !! help me 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges