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
1
Question by Kumacuda · Apr 03, 2015 at 08:03 PM · timercooldown

Making a boost for a spaceship with cooldown.

So I've been at this all day, but I'm making a little practice game that is similar to those old arcade space bullet hells, and I want a boost mechanic with a cool down timer, but can't seem to get unity to start the charge timer. This is my current code.

 :Code for moving the ship:
 
 public string GetKey;

 public float startTime;
 public string currentTime;
 public float chargeTime;    
 
 
 void Update () {
         
             
         updateBoost();
         if (chargeTime == 5) // <=== Not seeing the change and starting the countdown for the cool down
         {
             //run the use timer.
             chargeTime -= Time.deltaTime;
             currentTime = string.Format("{0:0.0}", chargeTime);
             print(currentTime);
             
             if (chargeTime <=0)
             {
                 startTime = 5;
                 print("You are ready to boost.");
                 GetKey = "t";    
             }
         }
         
         //Texture movement
         TextureOffset += ScrollSpeed * Time.deltaTime;
         
         GetComponent<Renderer>().material.SetTextureOffset("_MainTex", TextureOffset);    
 
         
             
     }
 
     void updateBoost(){        
 
         if (Input.GetKey(GetKey)){
             TextureOffset += ScrollSpeed * Time.deltaTime * 5;
             
             //run the use timer.
             startTime -= Time.deltaTime;
             currentTime = string.Format("{0:0.0}", startTime);
             print(currentTime);
             
             if (startTime <=0)
             {
                 chargeTime = 5;
                 print("You are out of fuel.");
                 GetKey = "r";
                 
             }
         }
         
         
         
     }



First time posting here, so I think this is everything I need to post. I'm kinda new at this.

Comment
Add comment · Show 6
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 _Kyle_1 · Apr 03, 2015 at 08:15 PM 0
Share

What do you have the variables set to in the Inspector?

avatar image Kumacuda · Apr 03, 2015 at 09:38 PM 0
Share

Get $$anonymous$$ey t Start Time 5 current Time nothing Charge Time 0

I have it change the key to "r" since it's the only way so far I've figure out how to get it to stop boosting.

avatar image _Kyle_1 · Apr 03, 2015 at 10:19 PM 0
Share

I've got it figured out, just let me post it and then the mods have to approve it.

avatar image Kumacuda · Apr 04, 2015 at 12:51 AM 0
Share

$$anonymous$$ods sure take their time...

avatar image Kumacuda · Apr 04, 2015 at 03:31 AM 0
Share

Yep, worked like a charm, thanks a ton!.

Show more comments

1 Reply

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

Answer by _Kyle_1 · Apr 04, 2015 at 03:26 AM

     public float startTime;
     public string currentTime;
     public float chargeTime = 0;
     //Added a boolean to disable boost so you don't have to change the key
     public bool boostLeft = true;


     void Update () {
         //Removed updateBoost() and added it to update() so it would be easier for me to figure out what was going on

         //Moved this, not really sure where it belongs
         TextureOffset += ScrollSpeed * Time.deltaTime;
         GetComponent<Renderer>().material.SetTextureOffset("_MainTex", TextureOffset);

         if (Input.GetKey("t") && boostLeft)
         {
             //Not really sure where this belongs, either
             TextureOffset += ScrollSpeed * Time.deltaTime * 5;
             startTime -= Time.deltaTime;
             currentTime = string.Format("{0:0.0}", startTime);
             //Added "Boost Left " to help with cleanliness
             print("Boost Left " + currentTime);
         }
         //Changed this from an if-else to separate if-statements so they are checked individually
         //Added "boostLeft &&) to make sure chargeTime isn't constantly set to 5
         if (boostLeft && startTime <= 0)
         {
             chargeTime = 5;
             boostLeft = false;
             print("You are out of fuel.");
         }

          //Changed to ">0" just in case you want longer or shorter charge times and for another reason I forgot
         if (chargeTime > 0)
         {
             chargeTime -= Time.deltaTime;
             currentTime = string.Format("{0:0.0}", chargeTime);
             //Added "Charging " to help with cleanliness
             print("Charging " + currentTime);
         
             if (chargeTime <=0)
             {
                 boostLeft = true;
                 startTime = 5;
                 print("You are ready to boost.");  
             }
         }
 }


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Cooldown Function Problem 1 Answer

Free 2d dash ability script! 2 Answers

Cooldown/Timer system (Javascript) 0 Answers

Laser fire time limit 0 Answers

.js Timer to prevent chatflood? 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