Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tobi003b · Jan 30, 2018 at 07:42 AM · c#script.gamerace

Race Game Start and Finish-line,Racing game start/finishline

Hi, I'm in the process of making a racing game, where I've come to the point where I only need to make, a start and finish-line, to the map and it's done. Can anybody help?,Hi, I'm in the process of making a racing, game, and I'm at the point where I just need a finish line, for my first map, and it's done. So I was wondering, if anybody knew how to make a finish line, with 3 laps?

Comment
Add comment · Show 1
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 ashishcw · Jan 29, 2018 at 11:17 AM 0
Share

Okay, first of all, I am unsure, as in why did you repeat your question twice? Secondly, its a bit confusing as you didn't mention anything specific, as in you are struggling to the graphical representation of finish line or backend code/functions.

Anyways, I will try to answer them both.

For the graphical representation, just mention if it's 2d or 3d game that you are making and try to search the asset store as I am sure there might be an asset useful to you.

About the coding/logic, try making a box collider with is trigger checked in an inspector view.

Place that box collider on the finish line.

Next, make custom script, which will be a lap counter for your game. Assu$$anonymous$$g, your cars/Player game object will have tag attached to it.

Now, use, ontriggerenter function in the script which you have attached earlier to the box collider. Try to check if the player object crossed the line, So every time, that tagged game object crosses the box collider, you increment the lap counter by 1.

Lastly, if(LapCounter >= 3){//FINAL CODE GOES HERE}

P.s. This is a vague explanation and not the final code to use in your game. But I tried to explain you the logic here. If you still have difficulty understand it, try to provide more information about your game. e.g. 1) Is your game 2D, 3D? 2) what do you want to achieve? 3) Images or short video of your problem?

will might increase the chances of better and quick resolution. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cycy · Jan 31, 2018 at 10:06 AM

Hi,

You may use a box collider at your start/finish line with a script in it who will count each time the player pass through it. When the counter reach 3 you stop the race.

Tell if you need further explications on how to do it and what to write in the script :)

See ya

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 tobi003b · Jan 31, 2018 at 04:49 PM 0
Share

Hi, thanks for the info about the box collider, and yes I would like to hear more about the scripting :)

avatar image Cycy tobi003b · Feb 01, 2018 at 02:18 PM 1
Share

Hi,

if you want we can share a collab, i could help you directly in the project :) tell me if you want.

Other wise, here how i see the script, tell me if you need more explanation or maybe some adjustment for your project :)

 string playerTag = "playerTagExemple"; // to recognize the player (via tag) 
 int lapCounter; // to count laps
 int maxNbOfLap; // set how many lap the player has to run before end

 void Start()
 {
     initialization();
 }

 /// <summary>
 /// To set the initial state of racce
 /// </summary>
 void initialization()
 {
     lapCounter = 0;
     maxNbOfLap = 3;
 }

 /// <summary>
 /// When the player Trigger the box collider at the start/finish line
 /// </summary>
 /// <param name="_objectWhichPassTheLine"></param>
 void OnTriggerEnter(Collider _objectWhichPassTheLine)
 {
     if (_objectWhichPassTheLine.gameObject.CompareTag(playerTag))
     {
         lapCounter++;  
     }
     checkLapCounter();
 }

 /// <summary>
 /// Check the lap counter to see how many lap the player did
 /// </summary>
 void checkLapCounter()
 {
     if (lapCounter == maxNbOfLap + 1) // +1 because the player will trigger the collider at the start.
     {
         endGame();
     }
 }

 /// <summary>
 /// You end the race when the player reach the max number of lap.
 /// </summary>
 void endGame()
 {
     //do whatever you need to.
     Debug.Log("The game is ended, the player did 3 lap");
     initialization();
 }
avatar image tobi003b Cycy · Feb 01, 2018 at 04:21 PM 0
Share

Hi, Thank you for the script, it looks very promising for my type of game :), but I just need to know, how do I use the "PlayerTag" string (is there a certain way to use?)? and (if this is possible) how do I make it work with two players? and about the "_objectWhichPassTheLine", do I need to change that? :)

Show more comments

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

453 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Can someone help me with my question with IENumerators in C#? 1 Answer

I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers

I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers

How to stop sound on trigger exit? 1 Answer

Multiple Cars not working 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