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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by javanoob · Aug 26, 2012 at 12:33 PM · triggercar

Show laptime after each lap ?

Hi guys I made a checkpoint script see below :) BUT I cannot seem to work out how to show the laptime after each lap completed ? can anyone help please ,its probably very simple but as you can probably tell from my script ,I am a Javanoob :p

heres the code

var time : float; var lapTime : float; var ckp = 0; var lap = 0;

function OnGUI(){ GUI.Box (Rect (10,10,110,100), "Racetime:" + time); GUI.Box (Rect (120,120,110,100), "Checkpoint : " + ckp/2); GUI.Box (Rect (240,10,110,100), "Laps" + lap);

if (lap==1) GUI.Box (Rect (540,10,400,100), "Laptime:" + (lapTime - time)); // This Shows as Zero ?

if (lap==2) GUI.Box (Rect (540,10,200,100), "You WON !");

}

function OnTriggerEnter(hit : Collider){

 if(hit.gameObject.tag == "Checkpoint1")

ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint2") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint3") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint4") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint5") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint6") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint7") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint8") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint9") ckp=ckp +1; if(hit.gameObject.tag == "Checkpoint10") ckp=ckp +1;
if (ckp==20) lap=1; if (ckp==40) lap=2; if (ckp==60) lap=3; if (ckp==80) lap=4; if (ckp==100) lap=5;

}

Comment
Add comment · Show 3
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 valax · Aug 26, 2012 at 04:49 PM 0
Share

could you put it on pastebin please?

avatar image javanoob · Aug 26, 2012 at 10:25 PM 0
Share

http://pastebin.com/Ph8ZwjhX

Im asking how to get the value of the time when the car hits the last checkpoint a,d show it with ongui ,say 1 $$anonymous$$ 37 seconds and display THAT moment in time .A$$anonymous$$ I making sense lol ?

avatar image Nightlithium · Aug 28, 2012 at 02:37 AM 0
Share

Try declaring laptime as a string ins$$anonymous$$d of a float.

1 Reply

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

Answer by Nightlithium · Aug 27, 2012 at 01:27 AM

You'll want to have timeStart only once, in the Awake() function, instead of in the Update() function. After that, you can find the current lap time by subtracting timeStart from the current time. Like so;

 function Awake() {
     var timeStart = Time.time; //Gets the time when the script awakes
 }

And then where you have the check to increment laps, currently written as;

 if (ckp==20)  lap=1; 

you just change it to;

 if (ckp == 20) {
     lap = 1;
     lapTime = Time.time - startTime; 
     //Takes the current time, and subtracts the start time from it,
     //leaving you with the amount of time in between as your lap time.
 }

And just have your OnGUI display lapTime in the appropriate box constantly, with a null value at the beginning of the race.

I'm a newbie too though, only got Unity a day or two ago, so take my advice with a grain of salt.

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 javanoob · Aug 28, 2012 at 09:42 AM 0
Share

If you only got Unity two days ago ,then I cannot wait to see what you will be able to do after a couple of months :)

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

Below script is a car controller and i want the car to boost when hit a trigger object. Still new with unity T^ T 0 Answers

Enter Car On KeyDown 1 Answer

How can I make a trigger detect Terrain? 0 Answers

Help with trigger zone 1 Answer

Lap timer using colliders 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