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 /
  • Help Room /
avatar image
0
Question by JoshuaTheJoker · Jan 19, 2016 at 02:02 PM · c#timer

Time wont reset

So, I am trying to set the script up so the timer resets either after pressing down a button, or when time runs out, but it is not resetting for either of them.

             public float deccelerationTime = 3.0f;


 void Start () 
 {
     deccelerationTime = Time.time;
 }        

 void FixedUpdate () 
 {
     deccelerationTime = 3 - Time.time;


     if (Input.GetKeyDown (KeyCode.S))
     {
         speed += gas * Time.deltaTime;
         deccelerationTime = 3.0f;
     }
     else if (deccelerationTime ==  0)
     {
         speed = speed / 2;
         deccelerationTime = 3.0f;
     }
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
Best Answer

Answer by toddisarockstar · Jan 19, 2016 at 02:58 PM

         var deccelerationTime:float;
               deccelerationTime = 3;
         var gas:float;
                gas=1;
         function Update(){
             speed = speed + gas * Time.deltaTime;
         
             if (Input.GetKeyDown ("s")) {speed=0;}
             if(speed>deccelerationTime){speed=0;}
         
         
         }
 

is this what you are trying to do?

Comment
Add comment · Show 6 · 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 JoshuaTheJoker · Jan 19, 2016 at 03:02 PM 0
Share

Not really. I want it so when I press S, I gain speed, and it resets the timer. If I dont press S, it halfs my speed and also resets the timer

avatar image toddisarockstar · Jan 19, 2016 at 03:16 PM 0
Share

Get$$anonymous$$eyDown happens on just the first frame the button is pushed Get$$anonymous$$ey will be true as long as the button is held down. does that help?

avatar image toddisarockstar · Jan 19, 2016 at 03:26 PM 0
Share
                    var deccelerationTime:float;
                  deccelerationTime = 3;
            var gas:float;
                   gas=1;
   var half:float;
  
  half=2; var timer:float;
  
            function Update(){
               
                timer = timer * Time.deltaTime;
   
                    if (Input.Get$$anonymous$$eyDown ("s")) { timer=0;}
                                                              
                    if (Input.Get$$anonymous$$ey ("s")) {  speed = speed + gas * Time.deltaTime;}
                    else{speed=half;}
   
    if(speed>deccelerationTime){speed=0;}
            
            
            }
   
   
  
  
avatar image JoshuaTheJoker · Jan 20, 2016 at 04:59 PM 0
Share

Not exactly what I was looking for. The S key does exactly what I want it to do, except, the timer I need has to either do 1 of 2 things

Reset back to 0 after hitting S -or- Reset back to 0 after three seconds have gone by.

The rest of the script I have figured out, this is the only thing I need really to finish up my small phone game.

avatar image JoshuaTheJoker · Jan 20, 2016 at 05:01 PM 0
Share

Ill also try to explain what my game is doing

If S key is pressed down, +2 speed. Reset timer (Holding it down will do nothing. Will have to tap to add more speed)

If not hit, speed/2. Reset timer.

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

62 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

Related Questions

Need help with making disappearing platforms. Error CS1525 1 Answer

I make a timing score script in unity 2D, how i make high score of time?? Script is as follow: 1 Answer

HH:MM:SS game clock with modifiable start time error 1 Answer

Timer float not evaluating correctly when I check if it's less than another number 3 Answers

Timer only goes for .02 seconds 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