OP unresponsive.
How to revert speed back to normal after changing with Key.
My question is, how can I get the speed of my player go back to normal after i'm done pressing a key? I have it set currently so that the player is on a fixed speed (5), and when you press the UpArrow it sets the speed to double. Without doing shotty code and hard coding the numbers back in, how can I set the speed back to whatever it was before?
Here is a picture of what my code looks like
http://puu.sh/jJLlo/d5514be538.png
The problem here that I forgot to mention was that it just sets the speed to double, so every time I hit the Up Arrow it doubles so 5, 10, 20, 40, etc.
Answer by NoseKills · Aug 22, 2015 at 02:17 AM
Store the speed before changing it and assign the stored value back when UP is released
     public float speed;
     public float previousSpeed;
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             previousSpeed = speed;
             speed *= RunMultiplier;
         }
         else if (Input.GetKeyUp(KeyCode.UpArrow))
         {
             speed = previousSpeed;
         }
     }
You should copy paste your code instead of attaching screenshots in the future. Use the 1010101 key to get it formatted as code.
Follow this Question
Related Questions
How do I slow down a quickly moving spaceship 0 Answers
My bullet won't go forward? Please check my script and advise me 2 Answers
Can anyone explain what an offset is? 0 Answers
Unity SpeedPad / boost pad 1 Answer
LookRotation with constant speed 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                