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 kapuscianyglab · Sep 30, 2013 at 07:41 PM · racing gamecheckpoints

Simple checpoint system in 3d racing game - some issues.

Hi

I make 3d racing game and I have some problems with checkpoints system. I found this tutorial http://www.youtube.com/watch?v=7NehsLWcFIU.

I have problem with using script in my 3d game. If I play game, unity show following error:

"NullReferenceException: Object reference not set to an instance of an object checkpoints.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Standard Assets/Scripts/checkpoints.js:14)"

I used scripts: CarCheckpoint.js and Checkpoints.js from tutorial. Files can be download from tutorial http://www.youtube.com/watch?v=7NehsLWcFIU

Where should I set "3d text"? To Camera or MainCamera?

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

2 Replies

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

Answer by Nomibuilder · Apr 08, 2015 at 07:20 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 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 Sorenzo · Apr 15, 2015 at 07:32 AM 1
Share

Thank You. It was helpful :)

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

You are welcome :)

avatar image rdgorodrigo · Aug 01, 2015 at 04:42 PM 0
Share

Hello Nomibuilder, I have the same script and I am having an issue with the static variables, I hope you can help me to solve this problem please. http://answers.unity3d.com/questions/1015525/static-variables-issue.html

avatar image
0

Answer by kapuscianyglab · Sep 30, 2013 at 08:40 PM

I found where I make mistake. I deleted from code this fragment in checkpoint.js: //Update the 3dtext Camera.main.GetComponentInChildren(TextMesh).text = "Checkpoint: "+(CarCheckpoint.currentCheckpoint)+" Lap: "+(CarCheckpoint.currentLap);

and I added this:

function OnGUI () { GUI.Label (Rect (10, 10, 200, 20), "Checkpoint: "+(CarCheckpoint.currentCheckpoint)+" Lap: "+(CarCheckpoint.currentLap));

 }

Sorry for unnecessary question.

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

15 People are following this question.

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

Related Questions

Individual racers passing checkpoints racing game unity 0 Answers

Reset function for AI car? 0 Answers

problem with arcade racer timer system 0 Answers

Implementing a Lap/Checkpoint System (Racing Game) 1 Answer

Endless runner distance calculation problem 2 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