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 HexStudio · Aug 15, 2020 at 08:15 AM · carsliderracingcar gamebar

Nitro bar setup

Hello. In my car game, I implemented nitro, when you apply it it multiplies the motortorque of the wheel colliders by two. But there's somethings I whant to do but i can't : I want to give the nitro a duration (for exemple, it lasts 4 seconds) and then i want it to take a time to recharge. I want to make a nitro bar associated with it (it shrinks as you use the nitro and grows as it recharges)

There is my nitro script :

*It is part of the car controller

 void FixedUpdate()
     {
         NitroSystem();
     }
 
 void NitroSystem()
     {
         if(inputManager.nitro)
         {
             nitroIsOn = true;
         }
         else
         {
             nitroIsOn = false;
         }
 
         if(nitroIsOn == true)
         {
             nitroValue = 5f;
             topSpeed = topSpeedValue * 2f;
         }
         else if (nitroIsOn == false)
         {
             nitroValue = 1f;
             topSpeed = topSpeedValue;
         }
     }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Spip5 · Aug 15, 2020 at 02:06 PM

 private float nitroAmount;
 public float maxNitroAmount = 5;
 public float nitroChargeSpeed;
 public float nitroUseSpeed;


 void Start()
      {
          NitroAmount = maxNitroAmount;
       }
 
 void NitroSystem()
      {
          if(inputManager.nitro)
          {
              nitroIsOn = true;
          }
          else
          {
              nitroIsOn = false;
          }
  
          if(nitroIsOn == true && nitroAmount > 0)
          {
              nitroAmount = Mathf.Clamp(nitroAmount  - (Time.DeltaTime * nitroUseSpeed),0,nitroAmount); 
              topSpeed = topSpeedValue * 2f;
          }
          else if (nitroIsOn == false)
          {
              nitroAmount = Mathf.Clamp(nitroAmount + (Time.DeltaTime * nitroChargeSpeed),0,maxNitroAmount);
              topSpeed = topSpeedValue;
          }
      }
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 Spip5 · Aug 15, 2020 at 02:08 PM 0
Share

And for the UI part, check this tutorial. logic for nitro is the same

If you need the bar to be fully recharged before using nitro again, I suggest using a coroutine with a timer. There are plenty of tutorials on how to do that

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

133 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

Related Questions

Rotate Sprite based on Car Velocity Non GUI 3D Speedometer 0 Answers

AI Car Problem 1 Answer

Automatic Car Moving Script 1 Answer

Best wheel collider values (forward friction,sidewards friction) for racing cars ? 1 Answer

Extremely simple car movement 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