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
0
Question by Colombian.kiwi · May 04, 2011 at 03:34 PM · timescorefinish

show times at the end of the game

Hello everyone!... Im working on this race game, What im having trouble with is basically showing the time on the top of the screen, and then when the game finnishes(when player gets to the goal) display a sign saying your time is:__(and show how long it took t to complete it)... Any ideas?? Thanks a lot!

Comment
Add comment
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

3 Replies

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

Answer by Sebastian 2 · May 04, 2011 at 03:48 PM

Hey Colombian,

you have to add a new Cube and disable the mesh renderer. Then place it on your Finish line. Now make a new tag like "FinishLine".

Now you do this with a script on youre car:

var time : float; var finished : boolean = false;

function Update{ //Add the time every Frame if race isnt finished if(finished == false){ time += Time.deltaTime; } }

function OnTriggerEnter(hit : Collider){ //if hit Collider is the Finish Cube if(hit.tag == "FinishLine"){ //Race is finished finished = true; } }

function OnGUI(){ if(finished){ //if Race finished GUI.Label(Rect(Screen.width / 2 - 100, 20, 200, 25), "Your Time: " + time); } else{ //if race isnt finished (only draw time) GUI.Label(Rect(Screen.width / 2 - 100, 20, 200, 25), "" + time); } }

Comment
Add comment · Show 4 · 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 Colombian.kiwi · May 04, 2011 at 04:49 PM 0
Share

Sounds pretty cool!... but its says: expecting (, found { any ideas why this is?

avatar image Sebastian 2 · May 04, 2011 at 06:32 PM 0
Share

Sry theres a mistake:

function Update()

avatar image Colombian.kiwi · May 04, 2011 at 09:55 PM 0
Share

thanx a lot! It was really helpful

avatar image Nakhchi · May 21, 2015 at 03:38 PM 0
Share

Hi, thank you for commend Sebastian 2. But do you know if there script with c#? because my car movement script is c#, so I can't use javascript which is you posted. Please I need help. Thank you

avatar image
1

Answer by Byterunner · May 04, 2011 at 03:40 PM

Store the time at the beginning of the race, then in your update function print out the current time minus the start time to display how long they've been racing on the top of the screen. When they reach the goal, save the current time minus the start time, and that's the time the race took.

Comment
Add comment · 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
1

Answer by Jesse Anders · May 04, 2011 at 03:41 PM

Although there may be more suitable solutions (depending on the circumstances), Unity's built-in GUI system is probably a good place to start. Using the GUI system, you can easily display text and graphics onscreen, which is what it sounds like you need here.

Displaying the total time at the end of the race is more of a program logic problem, and there are many ways it can be done (a simple state machine, loading a completely separate scene, etc.).

Those are fairly general answers, but the question itself is fairly broad. If you need further help with this, I'd recommend posting some more specific questions and specifying in more detail what exactly it is that you need help with.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Time Based Shooter 0 Answers

I need help for delete old highscore 0 Answers

How to call a function only once in Update 1 Answer

Calculating player distance meter? C# Unity2D 1 Answer

Score through hiting targets and time based score. 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