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 Moomooz · Jul 26, 2012 at 12:14 AM · cartutorial

Add Checkpoints and Laps Unity Car Tutorial

Hey there ,please please can someone point me in the right direction of adding a lap timer and checkpoint system to the Unity Car Tutorial ,I have tried loads of systems but cannot get one to work ,people say it's easy but I am stumped on this lol,any help will be greatly appreciated ,Its fine if its not possible ,I will stick to the Jcar one ,just would like another option if possible :)

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

5 Replies

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

Answer by Seth-Bergman · Jul 26, 2012 at 12:25 AM

for the timer:

 var time : float;
 var lapTime : float;
 
 function Update(){
 time = Time.time - lapTime;
 }
 
 function OnGUI(){
 GUI.Box (Rect (10,10,110,100), "current lap time:" + time);
 }
 
 function StartNewLap(){
 lapTime = Time.time;
 }

then use empty box colliders set to isTrigger for your checkpoints, and tag them:

 function OnTriggerEnter(hit : Collider){
 if(hit.gameObject.tag == "Checkpoint")
 //add more time?
 if(hit.gameObject.tag == "NewLap")
 StartNewLap();
 }

(this script would be on your car) hope this gets you started

Comment
Add comment · Show 3 · 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 Moomooz · Jul 26, 2012 at 12:59 AM 0
Share

At the risk of sounding like a complete idiot :p is this one script or two ?

avatar image Seth-Bergman · Jul 26, 2012 at 01:09 AM 0
Share

you could put it all in one

avatar image Seth-Bergman · Jul 26, 2012 at 01:29 AM 0
Share

No worries, it's really a comment anyway

Good luck!

avatar image
1

Answer by GluedBrain · May 05, 2013 at 10:02 AM

Laps and checkpoint sysyem

you might want to check this

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 Maverickthebest · Dec 21, 2018 at 03:46 PM 0
Share

Broken link

avatar image
1

Answer by Nomibuilder · Apr 08, 2015 at 07:18 AM

If you are using C# Language. Then here is the C# version of CheckPoint and Laps system.

Laps Script

 using UnityEngine;
 using System.Collections;
 
 public class Laps : MonoBehaviour {
     
     // These Static Variables are accessed in "checkpoint" Script
     public Transform[] checkPointArray;
     public static Transform[] checkpointA;
     public static int currentCheckpoint = 0; 
     public static int currentLap = 0; 
     public Vector3 startPos;
     public int Lap;
     
     void  Start ()
     {
         startPos = transform.position;
         currentCheckpoint = 0;
         currentLap = 0; 
 
     }
 
     void  Update ()
     {
         Lap = currentLap;
         checkpointA = checkPointArray;
     }
     
 }


Check Point Script

 using UnityEngine;
 using System.Collections;
 
 public class checkpoint : MonoBehaviour {
     
     void  Start ()
     {
 
     }
     
     void  OnTriggerEnter ( Collider other  )
     {
         //Is it the Player who enters the collider?
         if (!other.CompareTag("Player")) 
             return; //If it's not the player dont continue
         
 
         if (transform == Laps.checkpointA[Laps.currentCheckpoint].transform) 
         {
             //Check so we dont exceed our checkpoint quantity
             if (Laps.currentCheckpoint + 1 < Laps.checkpointA.Length) 
             {
                 //Add to currentLap if currentCheckpoint is 0
                 if(Laps.currentCheckpoint == 0)
                     Laps.currentLap++;
                 Laps.currentCheckpoint++;
             } 
             else 
             {
                 //If we dont have any Checkpoints left, go back to 0
                 Laps.currentCheckpoint = 0;
             }
         }
 
 
     }
 
 }


And Just Follow this tutorial to attach scripts on your Game Objects. Link

Comment
Add comment · Show 2 · 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 Sorenzo · Apr 15, 2015 at 07:36 AM 1
Share

thanks :)

avatar image Nomibuilder · Apr 15, 2015 at 07:36 AM 1
Share

Anytime :)

avatar image
0

Answer by Moomooz · Jul 26, 2012 at 02:05 AM

thanks ,I tried that and no errors:) (good sign) ,i'll work on from there and see what I can do ,the way you have laid it out does seem simple :) ,I'll work on thru the night and crack this hopefully :)

Getting there :)

Not quite working first attempt above lol :)

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
0

Answer by Moomooz · Aug 01, 2012 at 08:01 PM

var time : float; var lapTime : float; var ckp = 0; var lap = 0; function Update(){ time = Time.time - lapTime; }

function OnGUI(){

GUI.Box (Rect (10,10,110,100), "current lap time:" + time);

GUI.Box (Rect (120,120,110,100), "Checkpoint : " + ckp/2);

GUI.Box (Rect (240,10,110,100), "Laps" + lap);

if (lap==2) GUI.Box(Rect(500,500,200,200), "Race Won !! "); else; }

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 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 SwagGamez · May 06, 2015 at 04:41 PM 0
Share

This worked for me but if you go backwards it'll still increment therefore you can cheat. How can I prevent this? And how can I set a lap limit to end the race?

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

Question about rigidbody velocity 1 Answer

How do I create a mesh collider? 2 Answers

Beginner Car Control Script from FlatTutorials 3 Answers

UNEXPECTED TOKEN ) 1 Answer

Stuck in Car tutorial - Wheels 0 Answers


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